memory-allocation

Defragmenting C++ Heap Allocator & STL

I'm looking to write a self defragmenting memory manager whereby a simple incrementing heap allocator is used in combination with a simple compacting defragmenter. The rough scheme would be to allocate blocks starting at the lowest memory address going upwards and keeping book-keeping information starting at the highest memory address...

iPhone - Instruments ObjectAlloc GeneralBlock

Okay, I have been trying to days to lower the Net Bytes on GeneralBlock 16, I understand that a GeneralBlock is created by the iPhone's OS when creating its own object. Is it possible to lower this alloced memory? I have read in some places that GeneralBlock is something that you shouldn't worry about. True? ...

cooperative memory usage across threads?

I have an application that has multiple threads processing work from a todo queue. I have no influence over what gets into the queue and in what order (it is fed externally by the user). A single work item from the queue may take anywhere between a couple of seconds to several hours of runtime and should not be interrupted while processi...

executable failing in malloc_y function

we are trying to port our application from HP machine to AIX machine. it was running fine on HP machine but now its failing in malloc_y funtion. but we cant find any clue for this. who is calling this malloc_y function?? please advice. ...

Memory (sbrk) 16-byte aligned shifting on pointer access

I wrote a reasonably basic memory allocator using sbrk. I ask for a chunk of memory, say 65k and carve it up as needed for variables requesting dynamic memory. I free the memory by adding it back to the 65k block. The 65k block is derived from a union sizeof(16-bytes). Then I align the block along an even 16-byte boundary. But I'm gettin...

How can I get reference count for a managed object?

.NET profilers can show reference count to managed objects. How do they count them? ...

Storage of variables in memory

If I have a list of global variables like this... int a; char b; float c[10]; double d[3]; and I have an identical sequence of variables listed inside a class... class test_type { int a; char b; float c[10]; double d[3]; } is it guaranteed that the arrangement of all the variables in memory are identical. i.e. is 'b...

DataTemplate-driven View injection with MVVM

I have a container view that looks something like this <UserControl x:Class="Views.ContainerView"> <UserControl.Resources> <ResourceDictionary> <DataTemplate DataType="{x:Type viewmodels:AViewModel}"> <views:MyView /> </DataTemplate> <DataTemplate DataType="{x:Type viewmodels:BViewModel}"> <views:MyView /> </DataT...

Arranging global/static objects sequentially in memory

In C++, is it possible to force the compiler to arrange a series of global or static objects in a sequential memory position? Or is this the default behavior? For example, if I write… MyClass g_first (“first”); MyClass g_second (“second”); MyClass g_third (“third”); … will these objects occupy a continuous chunk of memory, or is the...

.NET Memory Limitations

I've written a little application for consuming memory either on disk, or RAM. The reasoning behind this is to test how certain parts of the application behave with small amounts of memory and testing various installers etc. with low disk space. It's quite useful, however currently I've had to limit them to 2Gb. Unfortunately sometimes ...

Can I use std::stack as object pool container?

I need to create a pool of objects to eliminate dynamic allocations. Is it efficient to use std::stack to contain pointers of allocated objects? I suspect every time I push the released object back to stack a new stack element will be dynamically allocated. Am I right? Should I use std::vector to make sure nothing new is allocated? Tha...

Where does stack for each program begin in memory?

Where does the stack of each program begin in memory? I understand that there is randomize address space option which will randomly choose an address. If the option is disabled, does each program start from the same address? What if we open two terminals and run two programs concurrently; will the system use same beginning address for ...

File uploading in asp.net

I'm wondering in what way HttpContext.Request keeps uploaded files in memory. Does is it hold them in RAM only or writes them in some temp dir on the HDD? How to control this process? ...

What is the best solution to replace a new memory allocator in an existing code?

During the last few days I've gained some information about memory allocators other than the standard malloc(). There are some implementations that seem to be much better than malloc() for applications with many threads. For example it seems that tcmalloc and ptmalloc have better performance. I have a C++ application that uses both mall...

Static allocation vs. Dynamic allocation vs. Automatic allocation

What are the differences among static, dynamic, and automatic allocation? ...

Does std::vector.pop_back() change vector's capacity?

If I allocated an std::vector to a certain size and capacity using resize() and reserve() at the beginning of my program, is it possible that pop_back() may "break" the reserved capacity and cause reallocations? ...

C++ Initialization list and memory alloc.

Hi, Is the following valid? class myClass { private: ... int m_nDataLength; boost::shared_array<int> m_pData; ... public: myClass(): ..., m_nDataLength(10), m_pData(new int[m_nDataLength]), ... { } } Am I right in assuming that the initialization will happen exactly in the order I've given in ...

Can I do a copy-on-write memcpy in Linux?

I have some code where I frequently copy a large block of memory, often after making only very small changes to it. I have implemented a system which tracks the changes, but I thought it might be nice, if possible to tell the OS to do a 'copy-on-write' of the memory, and let it deal with only making a copy of those parts which change. H...

Getting the size of the data of a Pointer

I tried the following code in order to see how to get size of the data of a pointer: #include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ char *test_char_ptr = "This is just a test"; int *test_int_ptr = (int *) malloc(16*sizeof(int)); for(int i = 0; i<16; i++){ test_int_ptr[i] = i; } printf("%s\n",te...

How do I find out where an object was instanciated using gdb?

I'm debugging an application and it segfaults at a position where it is almost impossible to determine which of the many instances causes the segfault. I figured that if I'm able to resolve the position at which the object is created, I will know which instance is causing the problem and resolve the bug. To be able to retrieve this inf...