Understanding “corrupted size vs. prev_size” glibc error

OK, so I’ve managed to overcome this issue. First of all – A practical cause to “corrupted size vs. prev_size” is quite simple – memory chunk control structure fields in the adjacent following chunk are being overwritten due to out-of-bounds access by the code. if you allocate x bytes for pointer p but wind up writing beyond x in regards to … Read more

How does jemalloc work? What are the benefits?

jemalloc first appeared for FreeBSD, the brainchild of one “Jason Evans”, hence the “je”. I would ridicule him for being egotistical had I not once written an operating system called paxos 🙂 See this PDF for full details. It’s a white paper describing in detail how the algorithms work. The main benefit is scalability in multi-processor and multi-threaded systems achieved, … Read more

Difference between malloc and calloc?

calloc() gives you a zero-initialized buffer, while malloc() leaves the memory uninitialized. For large allocations, most calloc implementations under mainstream OSes will get known-zeroed pages from the OS (e.g. via POSIX mmap(MAP_ANONYMOUS) or Windows VirtualAlloc) so it doesn’t need to write them in user-space. This is how normal malloc gets more pages from the OS as well; calloc just takes advantage of the OS’s guarantee. This means calloc memory … Read more

What is a Memory Heap?

Presumably you mean heap from a memory allocation point of view, not from a data structure point of view (the term has multiple meanings). A very simple explanation is that the heap is the portion of memory where dynamically allocated memory resides (i.e. memory allocated via malloc). Memory allocated from the heap will remain allocated … Read more