memory-allocation

Help me understand memory management in Objective-C and Cocoa

Don't shoot me, I know this must have been asked a thousand times... I am not comfortable with the lack of good documentation on Objective-C memory. I understand alloc, dealloc, retain, release and all that but there is some confusion left in my head. Is it just lazy programming or does Objective-C do some 'behind the scenes' automagi...

Where are constant variables stored in C?

I wonder where constant variables are stored. In the same memory area as global variables? Or on the stack? ...

How to find free memory within a specific address range.

I want to write a small amount of memory inside of a specific address range of my process. Example amount of memory to allocate: 5 bytes lower bound for address: 0x 00 40 00 00 upper bound for address: 0x 00 A0 00 00 The range in which I want to write is already allocated by the process. Therefore, I can't simply allocate new mem wi...

CUBLAS memory allocation error

I tried to allocate 17338896 elements of floating point numbers as follows (which is roughly 70 mb): state = cublasAlloc(theSim->Ndim*theSim->Ndim, sizeof(*(theSim->K0)), (void**)&K0cuda); if(state != CUBLAS_STATUS_SUCCESS) { printf("Error allocation video memory.\n"); return -1; ...

STL custom allocators to manage different memory spaces

I would like to use different instances of an STL custom allocator class to manage different memory spaces, and then be able to specify an allocator instance to an STL container such that each container only draws from its assigned memory space. But I don't see how I can do that. I see how I can pass an allocator type into the template...

Is there any danger in calling free() or delete instead of delete[]?

Possible Duplicate: ( POD )freeing memory : is delete[] equal to delete ? Does delete deallocate the elements beyond the first in an array? char *s = new char[n]; delete s; Does it matter in the above case seeing as all the elements of s are allocated contiguously, and it shouldn't be possible to delete only a portion of the ...

How does automatic memory allocation actually work in C++?

In C++, assuming no optimization, do the following two programs end up with the same memory allocation machine code? int main() { int i; int *p; } int main() { int *p = new int; delete p; } ...

java memory allocation fails (eclipse xp dell)

I have a problem at some customer pc's (new Dell PCs) windows XP Professional SP3, 4GB RAM if I try to start eclipse using -Xms256m -Xmx1024m than it fails reducing to -Xms256m -Xmx768m then it works any idea what could be wrong ? on my own machine I'm using OSX with Parallels VM running the same XP Prof SP3 then inside this XP I can...

Questions about C++ memory allocation and delete

I'm getting a bad error. When I call delete on an object at the top of an object hierarchy (hoping to the cause the deletion of its child objects), my progam quits and I get this: *** glibc detected *** /home/mossen/workspace/abbot/Debug/abbot: double free or corruption (out): 0xb7ec2158 *** followed by what looks like a memory dump of...

How do I allocate variably-sized structures contiguously in memory?

I'm using C++, and I have the following structures: struct ArrayOfThese { int a; int b; }; struct DataPoint { int a; int b; int c; }; In memory, I want to have 1 or more ArrayOfThese elements at the end of each DataPoint. There are not always the same number of ArrayOfThese elements per DataPoint. Because I have a ridicul...

Account memory usage with custom allocator

I'm using a custom allocator to account for memory usage in several containers. Currently I use a static variable to account for the memory usage. How could I separate this account across several containers without having to rewrite the allocator to use different static variables? static size_t allocated = 0; template <class T> ...

Freeing memory allocated in a different dll

I have an exe using a dll which is using another dll. This situation has arisen: In dll1: class abc { static bool FindSubFolders(const std::string & sFolderToCheck, std::vector< std::string > & vecSubFoldersFound); } In dll2: void aFunction() { std::vector<std::string> folders; std::string...

Dynamic Memory Reallocation using realloc

Hello All, I am learning C++. I am trying to learn this dynamic memory allocation. In the below code I am trying to allocate memory using malloc and realloc. int main (void) { char *g = (char*) malloc (sizeof(char) * 2); g = "ab"; g = (char*) realloc (g, sizeof(char) * 200); strcpy (g, "cdefg"); cout << g << endl; return 0...

STL containers on the stack and the heap

If std::vector and friends are self resizing, does that mean if I declare a vector like so: std::vector<string> myvec; Then it'll resize using more stack, whereas: std::vector<string> *myvec = new std::vector<string>(); Would resize using more heap? ...

Reuse NSURLConnection objects?

I've got an app that will be doing a fair amount of communication with a server over HTTP, and these connections may be overlapping. I'm planning to load the data asynchronously. I understand that there is a performance hit associated with allocating memory, so I figured the smart thing to do would be to keep a set of available connect...

How to allocate the memory from OS instead of increasing the JVM’s heap size?

I need to detect whether the file I am attaching to an email is exceeding the server limit. I am not allowed to increase the JVM heap size to do this since it is going to affect the application performance. If I don’t increase the JVM heap size, I will run into OutOfMemoryError directly. I would like to know how do allocate the memory...

Memory allocation in C

Hi, the following is a very very simple version of malloc() and seems to allocate some space to me, but apart from the fact that there is no free() and I don't check if I've overrun the allocated space, how can I check that the code is correct? Any obvious blunders that "C" experts would slap me for? #include <stdio.h> #include <unistd...

Linux optimistic malloc: will new always throw when out of memory?

I have been reading about out of memory conditions on Linux, and the following paragraph from the man pages got me thinking: By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available. This is a really bad bug. In case it...

C: Not explicitly returning constructed struct, but it still works

I write a 'constructor' function that makes a Node in C, compiled with Visual Studio 2008, ANSI C mode. #include <stdio.h> #include <stdlib.h> typedef struct _node { struct _node* next ; char* data ; } Node ; Node * makeNode() { Node * newNode = (Node*)malloc( sizeof(Node) ) ; // uncommenting this causes the program to fail. ...

List<T> and ArrayList default capacity

I have been looking at .NET's List and ArrayList implementations with Reflector. When looking at the Add(T item) I ran across this.EnsureCapacity(this._size + 1): public void Add(T item) { if (this._size == this._items.Length) { this.EnsureCapacity(this._size + 1); } this._items[this._size++] = item; this._ve...