memory-allocation

Stack Allocation in C

Is it bad style to design your simple C programs to allocate everything, or most everything, on the stack? ...

Can I switch the Visual C++ runtime to another heap?

My program uses a third party dynamic link library that has huge memory leaks inside. Both my program and the library are Visual C++ native code. Both link to the Visual C++ runtime dynamically. I'd like to force the library into another heap so that all allocations that are done through the Visual C++ runtime while the library code is ...

Reserved Memory Addresses?

Is there a list of reserved memory addresses out there - a list of addresses that the memory of a user-space program could never be allocated to? I realize this is most likely per-OS or per-architecture, but I was hoping someone might know some of the more common OSes and Arches. I could only dig one up for a few versions of windows: ...

Threading heap and stack

How memory is allocated in case of spawning a new thread, i.e how memory heap, memory stack, and threads are related? I know this is fundamental (.net framework concept) but somehow I am not much aware of this concept. ...

How do you dynamically allocate memory in Mac OS X assembly?

I would like to dynamically allocate memory from an assembly program that does not link against the standard C library. Since brk(2) and sbrk(2) are unavailable on Mac OS X (10.6.2), what are the alternatives? (I'm guessing that it involves a Mach call, but there seems to be little documentation around that) ...

NSMutableDictionary, alloc, init and reiniting...

In the following code: //anArray is a Array of Dictionary with 5 objs. //here we init with the first NSMutableDictionary *anMutableDict = [[NSMutableDictionary alloc] initWithDictionary:[anArray objectAtIndex:0]]; ... use of anMutableDict ... //then want to clear the MutableDict and assign the other dicts that was in the array of dic...

Objects leaking immediately from allocation using either new or [[Object alloc] init];

While running Instruments to find leaks in my code, after I've loaded a file and populate an NSMutableArray with new objects, leaks pop up! I am correctly releasing the objects. Sample code below: //NSMutableArray declared as a retained property in the parent class if(!mutableArray) mutableArray = [[NSMutableArray alloc] initWi...

How to read some bytes from BYTE*

I have BYTE pointer. For example the length of this BYTE array is 10. How can I read 4 bytes from 3 position BYTE array? Now I doing it so BYTE *source = "1234567890\0"; BYTE* tmp = new BYTE[4+1](); for(int i=0; i<4; i++) { tmp[i] = source[i+3]; } ...

Java Citrix Memory problem

Here is a puzzle that has got me baffled. We are running a Citrix server that provides access to two other servers, let's call them Application Server E and Application Server C. Each Application server is running the identical Tomcat environment. Users access through a web browser, a java based application (an applet). In one me...

Checking Available Memory allocation in C#

i need to create a function in my application to set its available memory usage. What i want to do is when the application is running, and it reaches to the set memory settings, i'll have to switch from saving to the memory to saving to a file to the local drive to avoid application hang. Is this a better way to do? What things to consid...

Unknown error in the memory in C

I have a 2D dynamic array. I enter a line of 0's after line which has a biggest number: void InsertZero(int **a, int pos){ int i, j; a = (int**)realloc(a, n * sizeof(*a)); a[n-1] = (int*)calloc(n, sizeof(**a)); d = 0; for(i = n-1; i > pos; i--){ for(j = 0; j < n; j++){ a[i][j] = a[i-1][j]; ...

malloc()/free() behavior differs between Debian and Redhat

I have a Linux app (written in C) that allocates large amount of memory (~60M) in small chunks through malloc() and then frees it (the app continues to run then). This memory is not returned to the OS but stays allocated to the process. Now, the interesting thing here is that this behavior happens only on RedHat Linux and clones (Fedor...

Which to use - "operator new" or "operator new[]" - to allocate a block of raw memory in C++?

My C++ program needs a block of uninitialized memory and a void* pointer to that block so that I can give it to a third party library. I want to pass control of the block lifetime to the library, so I don't want to use std::vector. When the library is done with the block it will call a callback that I have to supply and that will dealloc...

What's the purpose of having a separate "operator new[]" ?

Looks like operator new and operator new[] have exactly the same signature: void* operator new( size_t size ); void* operator new[]( size_t size ); and do exactly the same: either return a pointer to a big enough block of raw (not initialized in any way) memory or throw an exception. Also operator new is called internally when I crea...

How to use std::allocator in my own container class

I am trying to write a container class which uses STL allocators. What I currently do is to have a private member std::allocator<T> alloc_; (this will later be templated so that the user can pick a different allocator) and then call T* ptr = alloc_.allocate(1,0); to get a pointer to a newly allocated 'T' object (and used alloc_.con...

C vs. C++ for performance in memory allocation

Hi, I am planning to participate in development of a code written in C language for Monte Carlo analysis of complex problems. This codes allocates huge data arrays in memory to speed up its performance, therefore the author of the code has chosen C instead of C++ claiming that one can make faster and more reliable (concerning memory leak...

Memory allocation included in API

If there is the 'struct foo' and an APIs which handle foo, which is more flexible and convenient API? 1) API only initialize foo. User should declare foo or allocate memory for foo. The this style is like pthread_mutex_init/pthread_mutex_destroy. example 1) struct foo a; init_foo(&a);' example 2) struct foo *a; a = malloc(sizeof(st...

How to swap out a memory block?

How to make a block of memory allocated by malloc() or new: immediately swapped out, or lazily initialized. In fact, I'm trying to reserve an address space. How to accomplish this? PS. How to verify, from the user space, if a memory block is swapped out? ...

How well do zippers perform in practice, and when should they be used?

I think that the zipper is a beautiful idea; it elegantly provides a way to walk a list or tree and make what appear to be local updates in a functional way. Asymptotically, the costs appear to be reasonable. But traversing the data structure requires memory allocation at each iteration, where a normal list or tree traversal is just po...

.net real time stream processing - needed huge and fast RAM buffer

The application I'm developing communicates with an digital audio device, which is capable of sending 24 different voice streams at the same time. The device is connected via USB, using FTDI device (serial port emulator) and D2XX Drivers (basic COM driver is to slow to handle transfer of 4.5Mbit). Basically the application consist of ...