memory-allocation

When is it worth using a pointer to struct in a struct definition?

Sorry if the question isn't clear; I found it pretty hard to explain in one sentence. Say I have a struct with a member which is a struct, e.g. the following: struct A { struct B b; }; Lets say I intend instances of this structure to be heap-allocated always. Is there anything to be gained by changing it to this? (i.e. keeping a ...

How can you do C++ when your embedded compiler doesn't have operator new or STL support?

I am working on a group senior project for my university and I have run into a major hurdle in trying to get my code to work. The compiler that we have for our 8 bit Atmel microcontroller does not support the new or delete operators, and it does not support the C++ STL. I could program it in C, but I have to implement an A* algorithm w...

iPhone SDK mem management issues - EXC_BAD_ACCESS

I've been staring at this same issue for a long time now, and would really appreciate any help or suggestions. I'm sure its something simple, but I can't seem to find it. In my app delegate I'm loading up a bunch of accessory objects (an object I created, which supports NSCopying) with the following code: NSString *path = [[NSBundl...

Per thread memory allocation

Hello, I am working on a trace tool for multithread applications, more especially about memory allocation. I would like a per thread memory allocation. I know that when a thread do a malloc, the memory used is the global heap. I would like to trace which thread allocated how much memory. I did a wrapper upon malloc, incrementing value...

How are Process Explorer's memory metrics: WS Private, WS Shareable, WS Shared columns calculated?

I am continuing my saga to understand memory consumption by VB6 application. The option that seems to work best so far is to monitor various memory metrics at key points at run-time and understand where big memory hogs are. The measure driver to study this, is to understand how the application scalability in multi-user environment in Ter...

How do I snoop on another processes memory from .Net?

I'd like to attach to another process from a .Net console app and explore the data area. Specifically I would like to attach to the 'Spider Solitaire' app in Windows Vista as I am interested in seeing if the cards it deals out are solveable in all situations. Is this possible and if so which APIs should I be looking at? This is a 'just...

Memory allocation problem in HashTable

Please don't close this saying a duplicate question. I made an important change so not to confuse people, I resubmitted this much clearer codes. Please help me to solve this memory allocation problem. I'm working on a HashTable and this is what I've (partial codes only) main.c HashTablePtr hash; hash = createHashTable(10); insert(hash...

How much memory is allocated for each element when you dimension an array?

For instance, in VB.NET: Dim strArray(5) As String As I understand it, because this is an array, the computer will allocate contiguous memory locations for each of the 5 elements. But how much space is allocated for each of the five elements? What if I decide to put a 5MB block of text in position 2 of the array? Is it differen...

initializng a C array with repetitive data

I would like to initialize an array of structs, with the same element repetitively, ie struct st ar[] = { {1,2}, {1,2}, {1,2} }; However I do NOT want to run any code for that, I wish that the layout of the memory upon program's execution would be like so, without any CPU instructions involved (it would increase boot time on very slow...

Reading and writing to a buffer

Hi, I have 2 classes, one that writes multiple 96bit objects to a buffer (32bits at a time - 3x int32), and one that i want to read from the same buffer. The first class (Writer) reserves and area of memory and creates a pointer to the first 32bit area. 1) How do I write to the buffer safely (ignoring buffer overflow for now)... I nee...

dynamic structures in static memory?

GIVEN that you have a fixed area of memory already allocated that you would like to use, what C or C++ libraries will allow you to store a dynamic structure (e.g. a hash) in that memory? i.e. the hash library must not contain any calls to malloc or new, but must take a parameter that tells it the location and size of the memory it is pe...

Malloc of 2 bytes gives issues

I am trying to use a malloc of short, something like typedef union _SOME_STRUCT_ { struct { USHORT u:4; USHORT v:4; USHORT w:4; } x; USHORT word; } SOME_STRUCT, *PSOME_STRUCT; PSOME_STRUCT p = malloc (sizeof (SOME_STRUCT)); if (p) { p->x.u = 0; } free (p); // **** RANDOMLY CRASHING HERE **** I am d...

Under windows, how to allocate a "write combining" memory block?

The main motivation: to use the movntdqa assembler command to avoid stack pollution. This command only works with write combining memory (also called WS and USWC) ...

Are there any good custom allocators for C++ that maximize locality of reference?

I am running a simulation with a lot if bunch of initial memory allocations per object. The simulation has to run as quickly as possible, but the speed of allocation is not important. I am not concerned with deallocation. Ideally, the allocator will place everything in a contiguous block of memory. (I think this is sometimes called a...

Why is UILabel 0x0?

I'm loading a nib as: ContentViewController *theController = [[ContentViewController alloc] initWithNibName:@"ContentView" bundle:nil]; which has a label on it. The view controller has an IBOutlet of UILabel with a @property of retain and synthesized variable. When I load the nib as above from another class and reference the label's...

Am I correctly interning my Strings ?

I want to make sure I don't pummel the permgen space, so I'm carefully interning my strings. Are these two statements equivalent ? String s1 = ( "hello" + "world" ).intern(); String s2 = "hello".intern() + "world".intern(); UPDATE How I framed my question was totally different from the actual application. Here's the method where I...

Maximum Memory a .NET process can allocate

What is the maximum memory the garbage collector can allocate for a .NET process? When i compile to x64, Process.GetCurrentProcess.MaxWorkingSet returns about 1,4GB, but when i compile to AnyCPU (x64) the same number is returned. For x64 it should be more like the "Limit" value that is displayed in the Task Manager. How can i get the cor...

How do I find the physical memory size in Java?

I'm writing an installer that will tune the configuration of the product for the particular hardware on which it will be run. In particular, I want to determine how much physical RAM is installed in the system so I can estimate how much memory to allocate to the product when it runs. Ideally, I'd like to do this in a platform-independe...

Valgrind: Invaild read of size 8

I have been working on an open source project for awhile, http://gtkworkbook.sourceforge.net/, and recently ran into an issue that just seems like I am going in circles. I'm pretty sure there is a heap problem but I have been looking at this code too long to figure out exactly what it is. So, in brief, what I am doing is reallocating a...

Efficiency of repeated memory allocations in glibc

Below is my C wrapper for a Fortran ZHEEVR routine from well-known LAPACK numerical library: void zheevr(char jobz, char range, char uplo, int n, doublecomplex* a, int lda, double vl, double vu, int il, int iu, double abstol, double* w, doublecomplex* z, int ldz, int* info) { int m; int lwork = -1; int liwork = -1; int l...