memory-allocation

Memory management for intentionally memory intensive applications

Note: I am aware of the question Memory management in memory intensive application, however that question appears to be about applications that make frequent memory allocations, whereas my question is about applications intentionally designed to consume as much physical memory as is safe. I have a server application that uses large amou...

NSXMLParser Memory Allocation Efficiency for the iPhone

Hello, I've recently been playing with code for an iPhone app to parse XML. Sticking to Cocoa, I decided to go with the NSXMLParser class. The app will be responsible for parsing 10,000+ "computers", all which contain 6 other strings of information. For my test, I've verified that the XML is around 900k-1MB in size. My data model is to...

How much memory (RAM) can be allocated by an App on Blackberry

Hi guys, we are planing an app for blackberry app world and will have to load lots of textures and audiofiles. so we need to know how much memory the app can really allocate for a smarthphone with 64MB (RAM) thx for answers! ...

Android memory allocation

I am getting a "bitmap size exceeds VM budget" error. I have read that there is a 16MB memory limit. In this thread Romain Guy says that "you can only allocate 16 MB of memory for your entire application". However, my app must be running out of memory long before it reaches that limit. So my question is: how do I allocate memory to my ...

How to zero out new memory after realloc

What is the best way to zero out new memory after calling realloc while keeping the initially allocated memory intact? #include <stdlib.h> #include <assert.h> #include <string.h> #include <stdio.h> size_t COLORCOUNT = 4; typedef struct rgb_t { int r; int g; int b; } rgb_t; rgb_t** colors; void addColor(size_t i, int r, i...

Freeing CUDA memory painfully slow

I am allocating some float arrays (pretty large, ie 9,000,000 elements) on the GPU using cudaMalloc((void**)&(storage->data), size * sizeof(float)). In the end of my program, I free this memory using cudaFree(storage->data);. The problem is that the first deallocation is really slow, around 10 seconds, whereas the others are nearly inst...

Need some help understanding pointers and memory in C

I'm writing a bit of code for a class, but since I have no experience in C I'm a bit unsure of what the code I've written actually does. Particularly what the memory looks like. Here's the relevant bits: typedef struct listnode *Node; typedef struct listnode { void *data; Node next; Node previous; } Listnode; typedef struct...

C: Missing some logic with the pointers stuff...

I am writing my own string copy function. The following works: char *src, *dest; src = (char *) malloc(BUFFSIZE); //Do something to fill the src dest = (char *) malloc(strlen(src) + 1); mystringcpy(src, dest); void mystringcopy(char *src, char *dest) { for(; (*dest = *src) != '\0'; ++src, +dest); } But this doesn't work: char *sr...

"Memory could not be written" error passing an HGLOBAL from VB.Net to a C DLL

We are using visual studio 2008-My requirement is to allocate some memory, store data into that allocated memory and pass the memory address to a DLL written in C. But when try to pass this memory address to a function in that DLL my application crashes and shows the message "The memory could not be written". ''//Memory allocation Code ...

Static variable of procedure in Delphi

What is difference in memory management of variables a and b? Are they both similar static variables but visibility of b is local? Is it ok to declare static variable in procedure or function? const a: string = 'aaa'; procedure SubMethod; const b: string = 'bbb'; begin a := a + 'a'; b := b + 'b'; end; ...

When do you overload operator new?

Possible Duplicate: Any reason to overload global new and delete? In what cases does it make perfect sense to overload operator new? I heard you do it in a class that is very often allocated using new. Can you give an example? And are there other cases where you would want to overload operator new? Update: Thanks for all ...

How to initialise memory with new operator in C++?

I'm just beginning to get into C++ and I want to pick up some good habits. If I have just allocated an array of type int with the new operator, how can I initialise them all to 0 without looping through them all myself? Should I just use memset? Is there a C++ way to do it? ...

Any useful suggestions to figure out where memory is being free'd in a Win32 process?

An application I am working with is exhibiting the following behaviour: During a particular high-memory operation, the memory usage of the process under Task Manager (Mem Usage stat) reaches a peak of approximately 2.5GB (Note: A registry key has been set to allow this, as usually there is a maximum of 2GB for a process under 32-bit Wi...

When you exit a C application, is the malloc-ed memory automatically freed?

Let's say I have the following C code: int main () { int *p = malloc(10 * sizeof *p); *p = 42; return 0; //Exiting without freeing the allocated memory } When I compile and execute that C program, ie after allocating some space in memory, will that memory I allocated be still allocated (ie basically taking up space) after I exi...

Dynamic memory use in class member

Hello: I'm getting some odd behavior in one of my class members and it is truly throwing me for a loop but I'm certainly not seeing the issue (long week!) void MyFakeStringClass::readStream( iostream& nInputStream ) { // Hold the string size UINT32 size = 0; // Read the size from the stream nInputStream.read( reinterpr...

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! ...

BSS, Stack, Heap, Data, Code/Text - Where each of these start in memory?

Segments of memory - BSS, Stack, Heap, Data, Code/Text (Are there any more?). Say I have a 128MB RAM, Can someone tell me: How much memory is allocated for each of these memory segments? Where do they start? Please specify the address range or something like that for better clarity. What factors influence which should start where? ...

Inconveniences of pointers to static variables

I often use convenience functions that return pointers to static buffers like this: char* p(int x) { static char res[512]; snprintf(res, sizeof(res)-1, "number is %d", x)); return res; } and use them all over the place as arguments to other functions: ... some_func( somearg, p(6) ); .... However, this "convenience" ha...

Calloc inside function

Looking at this question that has just been asked: http://stackoverflow.com/questions/2231317/inconveniences-of-pointers-to-static-variables would doing something like this be considered bad practice, then? char* strpart(char* string, int start, int count) { char* strtemp; int i = 0; int j = 0; int strL = strlen(string); ...

Performing compiler allocation of memory on the stack of different sizes

I've been constructing my own compiler and one large part of it is obviously the register allocator, which matches up temporary variables with machine registers as efficiently as possible. On an architecture such as the x86 there aren't many registers so there are a number of spills in which variables must be stored in memory (the stack)...