Top "Malloc" questions

The malloc function performs dynamic memory allocation in C and is part of the standard library.

Overriding 'malloc' using the LD_PRELOAD mechanism

I'm trying to write a simple shared library that would log malloc calls to stderr (a sort of 'mtrace' if …

c malloc dynamic-linking
Explain this implementation of malloc from the K&R book

This is an excerpt from the book on C by Kernighan and Ritchie. It shows how to implement a version …

c pointers memory-management malloc
Why is it safer to use sizeof(*pointer) in malloc

Given struct node { int a; struct node * next; }; To malloc a new structure, struct node *p = malloc(sizeof(*p)); is …

c malloc
Can you define the size of an array at runtime in C

New to C, thanks a lot for help. Is it possible to define an array in C without either specifying …

c malloc dynamic-memory-allocation
Behaviour of malloc with delete in C++

int *p=(int * )malloc(sizeof(int)); delete p; When we allocate memory using malloc then we should release it using …

c++ malloc delete-operator
Why, or when, do you need to dynamically allocate memory in C?

Dynamic memory allocation is a very important topic in C programming. However, I've been unable to find a good explanation …

c malloc dynamic-memory-allocation
Dynamically allocating memory for const char string using malloc()

I am writing a program that reads a value from an .ini file, then passes the value into a function …

c++ c malloc const-char const-pointer
Malloc of arrays and structs within a struct

How does one malloc a struct which is inside another struct? I would also like to malloc an array of …

c struct malloc realloc
Why does the speed of memcpy() drop dramatically every 4KB?

I tested the speed of memcpy() noticing the speed drops dramatically at i*4KB. The result is as follow: the …

performance memory malloc memcpy cpu-cache
Memory Allocation/Deallocation Bottleneck?

How much of a bottleneck is memory allocation/deallocation in typical real-world programs? Answers from any type of program where …

performance optimization memory-management garbage-collection malloc