memory-allocation

.NET Pooling IAsyncResult Objects

Hi, Reading through the SendAsync, BeginAsync method illustrations of Sockets, I realized that it was suggested to pool SocketAsyncEventArgs instances saying that it is a better than BeginXX, EndXX async approach since each call creates an IAsyncResult instance. I thought it was not that a great practice to pool objects that can be ins...

C# class instance with static method vs static class memory usage

How does C#, or other languages for that matter, handle memory allocation (and memory de-allocation) between these two scenarios: 1.) A method on a static class is invoked. public Program { Foo foo = Loader.load(); } public static Loader { public static Foo load() { return new Foo(); } } 2.) A method is invoked...

At what exact moment is a local variable allocated storage?

Suppose we have the following: void print() { int a; // declaration a = 9; cout << a << endl; } int main () { print(); } Is the storage for variable a allocated at the moment function print is called in main or is it when execution reaches the declaration inside the function? ...

Do I trust ObjectAlloc or Leaks for analyzing my iPhone app?

When I run my iPhone app with "Leaks" (which has a section for Object Alloc), my app seems to be fine for memory allocation. However, when I run it with just the ObjectAlloc tool, the memory increases steadily as the app runs its main timer. (It is a timer based app). I'm not sure what to trust. I was just wondering if there are any ...

Memory allocation testing between two devices

I am testing my app in two different devices. My app is relies heavily on images(allocating and deallocating). I know I have a leak but I am just curious why I observe this. The behavior between the two devices is different. Device A crashes after 4 cycles of switching between views and Device B after 10 cycles, yet Device A has more fr...

Why malloc always return NULL

Hi, guys, My dev environment is VS2008, DX9, Windows XP. I try to add protection handling to the out of memory case. When malloc return NULL, I would page some resource to disk, and release the resources in the memory. But sometimes, malloc always return NULL, even if I release most of resources and process memory usage and VM size is o...

Where to start learning about linux DMA / device drivers / memory allocation

I'm porting / debugging a device driver (that is used by another kernel module) and facing a dead end because dma_sync_single_for_device() fails with an kernel oops. I have no clue what that function is supposed to do and googling does not really help, so I probably need to learn more about this stuff in total. The question is, where t...

Loading large multi-sample audio files into memory for playback - how to avoid temporary freezing

I am writing an application needs to use large audio multi-samples, usually around 50 mb in size. One file contains approximately 80 individual short sound recordings, which can get played back by my application at any time. For this reason all the audio data gets loaded into memory for quick access. However, when loading one of these f...

A `union` doubt

Suppose I define a union like this: #include <stdio.h> int main() { union u { int i; float f; }; union u tst; tst.f = 23.45; printf("%d\n", tst.i); return 0; } Can somebody tell me what the memory where tst is stored will look like? I am trying to understand the output 1102813594 that this p...

Pointer to pointer memory allocation, why is this wrong?

I am just trying to get my head around various pointer concepts and I have the following code: char** a = new char*; // assign first pointer to point to a char pointer char b[10] = "bla bla"; *a = new char; //assign second pointer a block of memory. -> This looks wrong to me!! (**a) = b[2]; So what is wrong with the s...

Memory allocation for a class that has deep inheritance in .NET

If I have classes A, B, C, D, E, and interfaces like X, Y, Z, and model a system like: class B : A, X class C : B, Y class D : C, Z class E : D If A is an abstract base class and E is the class of interest, when I create an instance of E, would it in turn create instances of A, B, C, D, X, Y, Z in addition to E? If that's the case, w...

C++: allocate block of T without calling constructor

I don't want constructor called. I am using placement new. I just want to allocate a block of T. My standard approach is: T* data = malloc(sizeof(T) * num); however, I don't know if (data+i) is T-aligned. Furthermore, I don't know if this is the right "C++" way. How should I allocate a block of T without calling its constructor? ...

Memory allocation in case of static variables

I am always confused about static variables, and the way memory allocation happens for them. For example: int a = 1; const int b = 2; static const int c = 3; int foo(int &arg){ arg++; return arg; } How is the memory allocated for a,b and c? What is the difference (in terms of memory) if I call foo(a), foo(b) and foo(c)? ...

C#. Struct design. Why 16 byte is recommended size?

I read Cwalina book (recommendations on development and design of .NET apps). He says that good designed struct has to be less than 16 bytes in size (for performance purpose). My questions is - why exactly is this? And (more important) can I have larger struct with same efficiency if I run my .NET 3.5 (soon to be .NET 4.0) 64-bit ap...

How objects (reference types- heap) communicate with variables stored on stack.

Hi all, as we know reference types are always stored on heap and value types are in stack memory. e.g. public Class A{ public int myInt=10; public void Display(){ } } here, if i create object of class A it goes in heap and myInt goes in stack right..? now, how class object (heap) interact with myInt public variable (stack)? ...

Small block allocator on Linux (or RedHat Linux) to avoid memory fragmentation

I know that there is an allocator for user applications than handles lots of small block allocation on HP-UX link text and on Windows XP Low-fragmentation Heap. On HP-UX it is possible to tune the allocator and on Windows XP it considers block of size less than 16 K as small. My problem is that I can't find any information about this ki...

How to allocate more memory for a buffer in C++?

I have pointer str: char* str = new char[10]; I use the memory block str points to to store data. How can I allocate more bytes for the buffer pointed to by str and not lose old data stored in the buffer? ...

How to give more memory to IntelliJ Idea 9

I am using IntelliJ IDEA 9. In the IDEA window On the bottom right corner I see the current memory usage, typically "224M of 254M" How do I give more memory to Idea so it may read like "224M of 512M" ? Thank you. ...

Dynamic memory allocation for 3D array

Possible Duplicates: Malloc a 3-Dimensional array in C? dynamic allocation/deallocation of 2D & 3D arrays How can i allocate 3D arrays using malloc? ...

strategy to allocate/free lots of small objects

hello I am toying with certain caching algorithm, which is challenging somewhat. Basically, it needs to allocate lots of small objects (double arrays, 1 to 256 elements), with objects accessible through mapped value, map[key] = array. time to initialized array may be quite large, generally more than 10 thousand cpu cycles. By lots I m...