So, as far as I know, malloc returns a pointer to a location in the heap.
sbrk() expands the heap by a minimum of 4k
If I could not use malloc, for reasons, would it be possible in c to allocate memory to a new member if a linked list (for example) by using an adress withing that 4k that has been gained by an sbrk() call, instead of a malloc?
Sorry if this is a dmub question :(
EDIT: The reason I can't use malloc is because my task is to create my own malloc and am told to use sbrk.
brkandsbrkhave been removed from POSIX; they are not portable. Somemallocimplementations usesbrk, but don't necessarily expect application code to be moving the break address, and so usingsbrkcan breakmalloc. Even if your code doesn't usemalloc, you might not be able to get away with breakingmalloc, because some other code in your process might be calling it.To obtain pages memory more directly from the operating system kernel relative to
mallocin a modern POSIX environment, a better choice is themmapfunction (withMAP_ANONandMAP_PRIVATEflags).