malloc

c++ RapidXml: reassign node pointer & mallocDebug

Hi, I started to use rappidXML a short time ago and I just noticed that when I reassign a node Pointer mallocDebug (I am using xCode on a mac) complains. This is what I do: xml_node<>* rootNode = doc.first_node("Root"); //find shaders xml_node<>* curNode = rootNode->first_node("Node1"); .... do something curN...

Modify malloc strategy for 2D Array so malloc succeeds

We recently received a report that our application will occasionally fail to run. I tracked down the problem code to this: struct ARRAY2D { long[] col; } int numRows = 800000; int numCols = 300; array = (ARRAY2D*) malloc(numRows * numCols * sizeof(long)) This allocation of 800 Mb can fail if the user doesn't have a large enough fr...

gdb gives an error, but program runs fine

I have a simple C program which has a pointer to a character array. To initiate it, I use malloc, and resize then set it x number of times later on in the program. When I resize it once with realloc, gdb doesn't show any errors, however, if I try calling the resize function again, gdb shows the following error: warning: Invalid Address...

Will malloc implementations return free-ed memory back to the system?

Will malloc implementations return free-ed memory back to the system? I have a long-living application with active memory allocation-deallocation. What behavior have ptmalloc 1-2-3, dlmalloc (glibc default), tcmalloc (google threaded malloc), solaris 10-11 default malloc and mtmalloc, FreeBSD 8 default malloc (jemalloc), Hoard malloc? ...

Extension wrapper malloc allocator for C++ STL

Apparently there is a “malloc_allocator” provided with gcc for use with STL. It simply wraps malloc and free. There is also a hook for an out-of-memory handler. Where can I find more about it? Where can I find its header file? I’m using gcc 4.x. ...

Getting exc_bad_access error only when mallocguard is enabled

I have an app for iPhone in development which works properly when the Malloc guard is not enabled. However when i try to enable the malloc guard i get the following error after the app is loaded. #0 0x95f65684 in objc_msgSend () #1 0x30506515 in NSPopAutoreleasePool () #2 0x30901697 in _UIApplicationHandleEvent () #3 0x32046375 ...

memory allocation limit for a 32-bit app on a 64-bit system

Hello SO, Is the max limitation for malloc (virtual heap I guess?) for a 32-bit app on a 64-bit system (Windows 2003 SP2 x64, to be specific) 2GB? I'm basically trying to push a program beyond that with no luck. So I was wondering if that holds true for ALL 32-bit apps on Win x64 bit platforms. Thank you! ...

C++ using getline() prints: pointer being freed was not allocated in XCode

I'm trying to use std:getline() but getting a strange runtime error: malloc: * error for object 0x10000a720: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug This is the code that produces this error: //main.cpp #include <iostream> #include <sstream> int main (int argc, char * const argv[]...

What are alternatives to malloc() in C?

I am writing C for an MPC 555 board and need to figure out how to allocate dynamic memory without using malloc. ...

C89: Access violation reading 0x00 (difficulty with malloc)

I am developing C89 on Visual Studio 2010 Ultimate Beta (Win 7). I don't think I'm using malloc() correctly. I am new to C, so please excuse the beginner question. The goal of my program is to count the occurrence of words in **argv using a tree. hist.c #include "tree.h" #include <stdlib.h> int main(int argc, char *argv[]) { unsi...

Dynamic allocation (malloc) of contiguous block of memory

For an assignment, I have to allocate a contiguous block of memory for a struct, but I'm first trying to do it with a 2D array of ints first and see if I understand it correctly. We had an example in the book that creates a block of memory for the pointer array (rows), and then initializes the cols and points the pointer to them. This ...

Is there a need to check for NULL after allocating memory, when kernel uses overcommit memory

It is general practice to check for NULL (whether memory is successfully allocated) after a malloc, some thing like void *ptr = malloc(10); if (ptr) { // do some thing usefull } else { // no memory. safely return/throw ... } with memory overcommit enabled in kernel, is there a chance of getting NULL. Should i follow the practice o...

Contiguous block of memory with malloc

I'm trying to create a contiguous block of memory in one function call that has the first part of the memory as pointer arrays to the other blocks. Basically, I'm trying to do: int **CreateInt2D(size_t rows, size_t cols) { int **p, **p1, **end; p = (int **)SafeMalloc(rows * sizeof(int *)); cols *= sizeof(int); for (end ...

calloc -- Usefulness of zeroing out memory

Hi, What is the advantage of zeroing out memory (i.e. calloc over malloc)? Won't you change the value to something else anyways? -Chris ...

Assigning memory to double pointer?

I am having trouble understanding how to assign memory to a double pointer. I want to read an array of strings and store it. char **ptr; fp=fopen("file.txt","r"); ptr=(char**)malloc(sizeof(char*)*50); for(int i=0;i<20;i++) { ptr[i]=(char*)malloc(sizeof(char)*50); fgets(ptr[i],50,fp); } instead of thi...

C, memory leak? Can not free some memory. Beginner

Hello I can't truly understand why the free process returns in an error. I got this code in C: int LuffarschackStart(void) { /* to avoid the program from closing */ char readEnd; int i = 0; board_type *board = malloc(sizeof(square_type)); if (board == NULL) { printf("Could not allocate the memory needed..."); scanf("%c", &...

Using sizeof() on malloc'd memory

Possible Duplicate: newbie questions about malloc and sizeof I am trying to read strings into a program. When I noticed that the strings were sometimes being corrupted, I tried the following code: void *mallocated = malloc(100); printf("sizeof(mallocated) = %d\n", sizeof(mallocated)); According to my program, the size of...

Android libc version and malloc implementation

Hello. What libc implementation is used in Android platform? What malloc implementation is used (ptmalloc or tcmalloc or anything other)? ...

Why dynamic allocation (linked lists/trees), c

I get confused why you use dynamic allocation and the concept of allocating enough memory for the data. So we are covering linked lists in my class and there is this code: NODE *BuildTree(NODE *p, const char *str) { if (p == NULL) size_t length = strlen(str) + 1; p = (NODE *)malloc(sizeof(NODE)); p->string = (char *)mal...

Debugging memory leaks with libMallocDebug

I want to use the MallocDebug app to find some memory leaks in my app. I'm running Mac OS X 10.6.2. Whenever I try and following the instructions listed in this guide, I get the following error: dyld: could not load inserted library: /usr/lib/libMallocDebug.A.dylib Trace/BPT trap I have verified that the .dylib file exists, and I get...