Top "Malloc" questions

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

How do I use strdup?

I am calling strdup and have to allocate space for the variable before calling strdup. char *variable; variable = (char*) malloc(…

c malloc strdup
Create a wrapper function for malloc and free in C

I am trying to create wrapper functions for free and malloc in C to help notify me of memory leaks. …

c memory-management memory-leaks malloc
Examining C/C++ Heap memory statistics in gdb

I'm trying to investigate the state of the C/C++ heap from within gdb on Linux amd64, is there a …

linux gdb malloc heap x86-64
How can I get the size of an array from a pointer in C?

I've allocated an "array" of mystruct of size n like this: if (NULL == (p = calloc(sizeof(struct mystruct) * n,1))) { /* handle …

c memory-management pointers malloc
When should I use free() in C?

The code works as it is supposed to, though it never frees the memory allocated by malloc(). I have tried …

c malloc free
Use of cudamalloc(). Why the double pointer?

I am currently going through the tutorial examples on http://code.google.com/p/stanford-cs193g-sp2010/ to learn CUDA. The …

c cuda malloc
C: Correctly freeing memory of a multi-dimensional array

Say you have the following ANSI C code that initializes a multi-dimensional array : int main() { int i, m = 5, n = 20; int **…

c memory-management memory-leaks free malloc
Under what circumstances can malloc return NULL?

It has never happened to me, and I've programming for years now. Can someone give me an example of a …

c memory-management malloc
Why does malloc initialize the values to 0 in gcc?

Maybe it is different from platform to platform, but when I compile using gcc and run the code below, I …

c linux gcc malloc
malloc: *** error for object: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug

Can someone help me figure out where I'm getting this error. I know it's probably a double deletion or something …

c++ c pointers malloc huffman-code