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

It seems like malloc is asking for too much memory

I have an STM32F0 application using the yagarto GCC compiler. I've implemented _sbrk newlib_stubs.c. The problem I'm running into is I'm calling malloc(256) an in-turn malloc in invoking _sbrk and asking for 4K of memory. My system only has a…
Kevin
  • 9,309
  • 12
  • 44
  • 51
0
votes
1 answer

Segmentation fault in sbrk(size_t)

My program is very simple, ... #define TO_INT(a) (*(int *)a) void *pool_head; void *pool_tail; ... pool_head = sbrk(BUF_LENGTH); if (pool_head == (void *)-1) { errno = ENOMEM; return pool_head; } pool_tail = sbrk(0); TO_INT(pool_head) …
thlgood
  • 1,275
  • 3
  • 18
  • 36
-1
votes
1 answer

Why does this code segfault on one machine but run fine on another?

This code segfaults on line 97 (according to gdb) on one machine (Linode) yet runs just fine on a different machine (personal) and I haven't really been able to figure out why. I tried ensuring that the heap was extended properly via sbrk but that…
-1
votes
2 answers

Abort in glibc while trying to use sbrk to reduce the size of the data segment

While working with glibc I tried to reduce the data segment using sbrk using a negative parameter, and found a most strange behaviour. I first malloc, then free it, then reduce data segment with sbrk, and then malloc again with same size as the…
Arc
  • 412
  • 2
  • 16
-1
votes
1 answer

C - sbrk(size) returns valid pointer but sbrk(0) is negative value

My code for the allocation is dat* data = NULL; data = sbrk(SIZE); if((int) data != -1){ return data }else{ printf("Not enough space"); } The sbrk(...) function returns a valid adress (0x603021) but when I go into gdb and and print sbrk(0) i…
BryG
  • 41
  • 9
-1
votes
1 answer

sbrk function and pointers in C program

Code: typedef long Align; union header { struct { union header *ptr; unsigned size; } s; Align x; }; typedef union header Header; ................ ................ ................ static…
mohangraj
  • 9,842
  • 19
  • 59
  • 94
-3
votes
1 answer

What is the program break in memory?

I am into reading reading a article talking about allocating space for pointers that does not say exactly what the PROGRAM BREAK" is but mentions it. I need to know what the program break is. If I create say a pointer to a memory space with…
1 2 3 4 5 6
7