memory-allocation

How to prevent unnecessary memory use in recursive functions

I've just written a recursive function and it dawned on me that all the variables I use within the function will remain allocated in memory until recursion breaks. If I am recursing a large number of times or allocating large amounts of memory for variables not used in the consequent recursive function call, could this lead to alot of w...

My allocated memory is beeing written to

Im writing a project in Objective-C but I'm relying quite much on plain old C since there's OpenGL involved. I have a data blob that I read to memory from a file in the following way: NSString *path = [[NSBundle mainBundle] pathForResource:@"iPadTest" ofType:@""]; NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:path]; dat...

What is the preferred way of allocating C++ class member data?

Let's say I have a class that allocates some arbitrary member data. There are two common ways that I have seen used (I know that there are others): class A { public: A(); ~A(); //Accessors... private: B *mB; } A::A() { mB = new B(); } A::~A() { delete B; } Versus... class A { pub...

Pointer mismatch for actual parameter?

I have a function which creates an array of pointers. The function which allocates the memory returns the new memory pointer through a parameter passed to the function. The simplest code which can reproduce the problem is as follows: void foo (void** new_mem, size_t bytes) { *new_mem = malloc(bytes); } int main (void) { int**...

How to terminate program in C++

Hi. When I exit my C++ program it crashes with errors like: EAccessViolation with mesage 'Access violation at address 0... and Abnormal Program Termination It is probably caused by some destructor because it happens only when the application exits. I use a few external libraries and cannot find the code that causes it. Is there a f...

iPad Application jettisoned while Allocations Instrument shows no unusual memory usage

I'm seeing my app being jettisoned due to low memory. In trying to track down the problem, I ran the app through the Allocations instrument. Unfortunately, I couldn't see any problem with the memory usage when it was killed. At the time of ejection, the app was playing a video, and had been for about 45 seconds. There were no touches or...

Setting a memory limit on my AI algorithm?

I am working on a Tetris AI implementation. It is a GUI application that plays the game by itself. The user can manipulate a few parameters that influence the decisions made by the AI. The basic algorithm goes as follows: Start a new thread and clone the current game state to avoid excessive locking. Generate a list of all possible fut...

When a third-party C function returns a pointer, should you free it yourself?

There are many functions (especially in the POSIX library) that return pointers to almost-necessarily freshly allocated data. Their manpages don't say if you should free them, or if there's some obscure mechanism at play (like returning a pointer to a static buffer, or something along these lines). For instance, the inet_ntoa function r...

Memory Profiling in the iphone

Hi Can any one guide me in clearing the memory leaks in the iphone code. in xcode editor it does not shows any issues, so i hav uploaded my app to the AppleStore. they rejected my app. so kindly help me what is my issue? how to rectify it. Thanks in advance ...

Tips for saving memory when coding under android ?

Hi all, Im currently developing a software under android and im getting quite quickly some OutOfMemoryException.... I did modified some part of my code to use more static variables instead of making new allocation with the "new" operator but is there any things else to do ? or any other tips ? Any advices would be welcome. Thanks. ...

How to alloc more than MaxInteger bytes of memory c#

Hi, I wish to allocate more than MaxInteger bytes of memory. Marshall.AllocHGlobal() expects an integer - so I cannot use this. Does anyone know of another way? ...

Pointer (trick) interesting question. Memory Reference

update, this question was based on this code http://jeffreystedfast.blogspot.com/2010/01/weird-bugs-due-to-gcc-44-and-strict.html One trick question about C pointer. Read code snippet below and try explain why the list value changed ? tail has the memory address of list. how is possible list be changed below ? typedef struct _node ...

Lazy image loading & unloading memory allocation problem.... Aaaargghhh ...

Hi there. I am building a scrollview which swipes through 100 images of houses. It works. But.... For every image viewed the allocated memory inscreases by 2.5 MB. In the end the app crashed because it ran out of memory. Even if I use the same image as specified in the code below, I run out of memory because of the memory allocations. ...

For which kind of applications can the Garbage Collector become a concern?

Because of their efficiency, most of the Garbage Collector algorithm are inoffensive in a lot of applications. The "collection" of objects does however require a small overhead cost in order to scan the stack and to liberate non referenced object from the heap. I know one part of the answer is "it depends". However, I would like to kno...

Fatal error: Allowed memory size, but it shouldn't be

I'm porting an installation of Joomla, and I'm getting this error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 116 bytes) in in \wwwroot\libraries\joomla\error\exception.php on line 117 I've tried upping the limit, but that doesn't help (well, it wouldn't, it's only trying to allocated 116 bytes) ...

Creating a scoped custom memory pool/allocator?

Would it be possible in C++ to create a custom allocator that works simply like this: { // Limit memory to 1024 KB ScopedMemoryPool memoryPool(1024 * 1024); // From here on all heap allocations ('new', 'malloc', ...) take memory from the pool. // If the pool is depleted these calls result in an exception being thrown. ...

Script/Tool that gives memory locations accessed ?

I have an application and I want to make a trace of all the data memory locations that it accesses. Is there any script or tool that can help me retrieve the memory locations accessed by my application ? ...

Where can I find a c++ memory allocator testbed?

Possible Duplicate: Benchmarks used to test a C and C++ allocator? Hello all, I've recently written an STL compatible custom allocator + memory manager, and I need a good (preferably multi-threaded) testbed to verify that it's working correctly. I could roll my own, but I imagine there are pretty good ones out there that hav...

"pointer being freed was not allocated" Memory block will not deallocate for some reason.

Hello. I'm struggling to find why I can't free a memory block. Something must be wrong with the pointer. A memory block for a structure is made in a function and the pointer used is stored in an array. Later the pointer is taken from the array to be used to free the memory. I've figured out which free it is. I've placed "//This one" nex...

Proper memory allocation?

How would I only allocate as much memory as really needed without knowing how big the arguments to the function are? Usually, I would use a fixed size, and calculate the rest with sizeof (note: the code isn't supposed to make sense, but to show the problem): #include <stdarg.h> #include <stdio.h> #include <stdlib.h> int test(const cha...