Questions tagged [sbrk]

**sbrk** is a basic memory management system call used in Unix and Unix-like operating systems to control the amount of memory allocated to the data segment[clarification needed] of the process.

sbrk is a basic memory management system call used in Unix and Unix-like operating systems to control the amount of memory allocated to the data segment[clarification needed] of the process. These calls are typically made from a higher-level memory management library such as malloc. In the original Unix system, brk and sbrk were the only ways in which applications could acquire additional data space; later versions allowed this to also be done using the mmap call

97 questions
0
votes
1 answer

Why do I hit Invalid write/read after sbrk (recoding mini malloc)?

I'm trying to recode a mini malloc using sbrk() and implementing a best-fit algorithm. I added a main to test my malloc along with my free(). Next thing a Segfault even though some of the values I tried to malloc in the main appear to be allocated…
0
votes
1 answer

How to free the heap memory in MIPS

For learning purposes, I'm trying to implement a stack in the heap memory. When I push something I just need to do the systemcall sbrk, and that's fine. When I proceed with a pop I can retrive my value, but I can't free the allocated space. Is there…
Vavaste
  • 139
  • 1
  • 5
0
votes
0 answers

Why would I get an error like this when calling sbrk()?

So I call sbrk like this: void *return_value = sbrk(1024); And when I debug it is giving me this error on that specific line: __GI___sbrk (increment=1024) at sbrk.c:32 32 sbrk.c: No such file or directory. Why would this be? And what is this…
Art smart
  • 11
  • 1
0
votes
0 answers

warning: implicit declaration of function 'sbrk' after Importing unistd.h

Could someone please tell me how to solve this problem described in the title? I've searched for a long time but still not found a solution yet. Update: I'm using window system
o o
  • 145
  • 6
0
votes
1 answer

C++ Malloc Doesn't call mmap or brk?

On ubuntu 18.04 I wrote the following c program and ran it with an input of 100 #include #include #include int main() { int x; scanf("%d", &x); usleep(1); void *tmp = malloc(x); usleep(1); …
user16363840
0
votes
1 answer

How to Convert Void* into size_t?

I have the following function: size_t calc_allign(size_t num) { return ((num + 7) & (-8)) - num; } And want to use it like this: int start_allign = calc_align (sbrk(0)); But I am getting error: error: no matching function for call to…
user16363840
0
votes
1 answer

Can I enforce sbrk return address to be within a certain specific range?

I want to make sure the return address of sbrk is within a certain specific range. I read somewhere that sbrk allocates from an area allocated at program initialization. So I'm wondering if there's anyway I can enforce the program initialization to…
AetX
  • 193
  • 6
0
votes
0 answers

sbrk() - cast to pointer from integer of different size

I am trying to implement my own heap memory allocator, by allocating memory via sbrk() system call, and managing the return buffer. void *sbrk(intptr_t increment); return value: From man sbrk: On success, sbrk() returns the previous program…
Adam
  • 2,820
  • 1
  • 13
  • 33
0
votes
1 answer

does brk and sbrk round the program break to the nearest page boundary?

My question is as tilte says, accroding to my text book int brk(void *end_data_segment); The brk() system call sets the program break to the location specified by end_data_segment. Since virtual memory is allocated in units of…
codesavesworld
  • 587
  • 3
  • 10
0
votes
1 answer

printf uses sbrk, conflicting with custom memory allocator

Hi I have Written a memory allocator, and works perfectly. I use sbrk/brk for page allocation and deallocation. But it all breaks the moment i start printing information using printfs. Googling shows that - printf internally does use sbrk also. So,…
Abhishek Sagar
  • 1,189
  • 4
  • 20
  • 44
0
votes
1 answer

Need to align memory on a power of 2 and align the program break on a multiple of 2 * getpagesize() in C

I'm re-coding the malloc function using brk, sbrk & getpagesize() I must follow two rules: 1) I must align my memory on a power of 2 It means: If the call to malloc is : malloc(9); i must return them a block of 16 byte. ( the nearest power of…
0
votes
2 answers

Do you specifically need malloc to allocate memory to new elements of a linked list

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)…
Real Name
  • 19
  • 5
0
votes
3 answers

Are padding bytes considered allocated or unallocated in a memory allocator?

I am writing a custom memory allocator in my program and trying to better understand what is considered allocated vs unallocated memory. I am told that for a basic, "naive" sbrk() memory allocator, calls to sbrk() must provide a size aligned to (a…
the_endian
  • 2,259
  • 1
  • 24
  • 49
0
votes
1 answer

Needing advice for implementing malloc and free in C

For school, I need to write a program that uses my own implementation of malloc and free. I need to be able to report on all the chunks of memory in my 'heap', whether it's allocated or not. I feel like I've written good code to do so, but…
ScottyD
  • 25
  • 3
0
votes
1 answer

After importing unistd.h, compiler states that sbrk() is an implicit declaration. Why is this?

I'm trying to implement malloc on CentOS, but I keep getting the error: malloc.c: In function ‘malloc’: malloc.c:11:5: error: implicit declaration of function ‘sbrk’ [-Werror=implicit-function-declaration] mem_ptr = sbrk(SIXTY_FOUR_K); /*…
Jacob Marshall
  • 182
  • 2
  • 11