101 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
2
answers
92
views
What difference between brk() and syscall(SYS_brk,)
man 2 brk says:
int brk(void *addr);
brk() sets the end of the data segment to the value specified by addr ...
On success, brk() returns zero. On error, -1 is returned, and errno is set to ENOMEM.
...
1
vote
0
answers
59
views
Not able to merge free blocks together in my simple, custom, memory allocator
I am trying to implement a simple memory allocator. Essentially trying to copy the function malloc() and free(void *ptr) in C.
I initialize a region of memory using sbrk(). In my custom malloc ...
0
votes
2
answers
95
views
Why does printing cause the heap break to increase by this much?
I wrote the following program,
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include "rand.h"
int main (int argc, char* argv[]) {
...
Addem's user avatar
- 4,013
0
votes
0
answers
112
views
How does sbrk in MIPS properly get called
I'm trying to learn MIPS and implement a dynamic memory allocation depending on the size of the number of values I need to store, so I'm using sbrk in my allocation of space. The problem arises that ...
2
votes
1
answer
125
views
Does sbrk(0) also allocate memory behind the scenes? No segfault when I store above 2K the break
I am learning how sbrk, brk, mmap etc work and what they offer. I am writing a very basic code like this
int main(int argc, char* argv[]) {
void* f1 = sbrk(0);
int* newarr = (int*)f1;
for(int i=0;...
3
votes
0
answers
105
views
Efficient 2 pass using heap memory
I have an algorithm that requires making two passes a file's data. The file may be stdin or stream (like a |) since this is a command line tool, which makes me unfortunately (to the best of my ...
1
vote
0
answers
66
views
Can the pointer returned by sys _brk overlap the stack on Linux?
Based on info in https://man7.org/linux/man-pages/man2/brk.2.html, the brk Linux system call works like this:
void *sys_brk(void *desired_break) { return (void*)syscall(SYS_brk, desired_break); }
It ...
pts's user avatar
- 88.7k
-1
votes
1
answer
134
views
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 ...
0
votes
1
answer
61
views
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 ...
-1
votes
2
answers
753
views
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, ...
3
votes
2
answers
1k
views
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 ...
0
votes
0
answers
224
views
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 ...
8
votes
4
answers
7k
views
Where does malloc() allocate memory? Is it the data section or the heap section of the virtual address space of the process?
Ever since I was introduced to C, I was told that in C dynamic memory allocation is done using the functions in the malloc family. I also learned that memory dynamically allocated using malloc is ...
1
vote
0
answers
454
views
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