malloc

C or C++ Heap Memory Management Implementations

Can someone point me to a few open source heap implementations which are not part of a huge library like GLIB. I need one with the following features: Single Threaded The whole heap can be freed with a single call. Small footprint because i need to use one heap for each list/tree widget in my GUI. I think there should be a lot of ex...

Reading a string is not going properly

Hey guys, i'm working on a program that gets a postfix expression and calculates it.. I have two functions: Converts infix to postfix Calculate the postfix When I try small expressions, like 1+1 or (1+1)*1, it works fine but when i use all the operands I get something nasty, Here is the example: 2*2/2+1-1 gets something like: 222/*...

How malloc works?

Possible Duplicate: How do free and malloc work in C? Consider a scenario where i have to allocate some 20 bytes of memory through malloc. For the function call to malloc() to be successful, should the 20 bytes be available contiguously in memory or can it be scattered? For eg, in the above case, if there are 4 or 5 chunks of ...

Is the return value of malloc a virtual or physical address?

Is the address returned by malloc a virtual address or is it the actual physical address where the memory is allocated? Edit: I read somewhere "In some implementations, calling free() releases the memory back to the system and in others it is released back to the process". Does "releasing back to the system" imply that the memory is th...

How much data can be malloced at a time? what is the limit in modern OS such as Linux?

Hi, How much data can be malloced and how is the limit determined? I am writing an algorithm in C that basically utilizes repeatedly some data stored in arrays. My idea is to have this saved in dynamically allocated arrays but I am not sure if it's possible to have such amounts malloced. I use 200 arrays of size 2046 holding complex dat...

Filling 4 variable in a struct type and using malloc

I need to write a simple program that ask the user to insert 4 double type variable in a struct variable data. struct Data { double a; double b; double c; double average; }; struct Data *ptr_name; int i; First, ask user the size: printf("Please enter the size:"); scanf("%d", &size); Then, use ...

Malloc only once for ALL adapters when using GetAdaptersInfo()?

I looked at the GetAdaptersInfo() sample in MSDN: http://msdn.microsoft.com/en-us/library/aa365917%28VS.85%29.aspx and noticed that while the sample attempts to iterate through ALL adapters, it only allocates memory for the first one. Is this a bug? If not, why not? Do all adapters have the same info size? To further clarify my ques...

what is aligned memory allocation?

I also want to know whether glibc malloc() does this? ...

malloc error and simulator crash

I constantly get malloc error : double freed.... The echoTime function is being called by a button. When i press the button again before the timer ends it gives me the malloc error. When i press the button after the timer finished to start it again, the simulator hangs. Does anyone know what is wrong with the following piece of code: -(...

using malloc() for double pointers

Hi there, a malloc question. First, I generate some strings. And second, I allocate none-space for copying pointers which point to those strings. At this moment the program should probably crash, since I ve tried to copy those pointers to nowhere, but it doesn’t crash. How is it possible? Any comments would be appreciated. #include <...

One large malloc versus multiple smaller reallocs

Hello. Sorry if this has been asked before, I haven't been able to find just what I am looking for. I am reading fields from a list and writing them to a block of memory. I could Walk the whole list, find the total needed size, do one malloc and THEN walk the list again and copy each field; Walk the whole list and realloc the block of...

Initializing array inside struct - C?

Seem to have a memory allocation problem and think it's because in my struct, there is a pointer to an array of another struct. However, I'm not initializing this array and not sure how: typedef struct listitem { struct listitem *next; Entry *entry; } ListItem; typedef struct list { ListItem *table[100]; } List; List *init...

Reading a file to char array then malloc size. (C)

Hey, so lets say I get a file as the first command line argument. int main(int argc, char** argv) { unsigned char* fileArray; FILE* file1 = fopen(argv[1], "r"); } Now how can I go about reading that file, char by char, into the char* fileArray? Basically how can I convert a FILE* to a char* before I know how big I need to ma...

How to initialise a pointer to pointer struct in C?

I have a struct which is a node, and another which is a list of these nodes. In the list struct, its an array of nodes, but instead of an array, it's a pointer to pointer with a size integer: typedef struct node { struct node *next; MyDef *entry; } Node; typedef struct list { Node **table; int size; } List; List *init...

Why does this malloc not work in C?

Just trying to make a kind of hash table with each node being a linked list. Having trouble just initializing the space, what am I doing wrong? #include <stdlib.h> typedef struct entry { struct entry *next; void *theData; } Entry; typedef struct HashTable { Entry **table; int size; } HashTable; int main(){ HashTable *ml; ml =...

Free() returned char pointer doesn't remove it from memory?

Basically the problem comes down to this: I load a file, write all the each character into a char* variable which has malloc() the length of the file. Then I return that variable and print it, then I free() the memory for that variable and try to print the variable again which does print it. I'm very new to C so there is probably som...

How to malloc "MyDef ** t" to a specific length, instead of "MyDef * t[5]" in C

A struct like the following works fine, I can use t after calling malloc(sizeof(mystruct)): struct mystruct { MyDef *t[5]; }; I want to be able to dynamically set the length of the array of MyDef, like the following: struct mystruct { MyDef **t; int size; }; What do I need to do additionally to malloc(sizeof(mystruct)) to get th...

glib memory allocation VS std *alloc and free

I tend to use std *alloc/free functions to allocate/free dynamic memory in my C programs. I wonder if there are any good reasons to use the GLIB Memory Allocation functions instead of the std ones. I'd be grateful if the comunity could point out situations where either of these solutions is a winner/looser. I am also interested in perf...

Objective C free command not working with malloced memory

Hello All, I have an object that holds a pointer to some malloced memory, when I come to dealloc the object I use the free command to free up the malloced memory, how ever the free command appears to be absolutely doing nothing and I'm getting large memory leaks as a result. I have confirmed that the dealloc command is being executed. ...

Pointer to an array of pointers to Linked lists

hey guys right so i have been at this problem for the last 6 hours and have been hitting google like mad to no avail. Right I need a pointer to an array. This array contains pointers to Linked lists. Im going to have to malloc it since I dont know the array size until runtime. LList **array this was my first thought but this just give...