I think I've got a good grasp on how to handle memory in C++ but doing it in C is different I'm a bit off.
In C++ I've got constructors and destructors, I've got the pretty straightforward new and delete and I know how to encapsulate it using RAII, using with smart pointers and within classes.
However in C I can't handle malloc and fre...
I have a program in which I want to be able to store certain data (dynamically allocated blocks), on disk for reduced memory usage and persistence.
My first thought was to write my own custom allocator which managed the content of files on the disk, but I want to see what alternatives there are too.
I've looked into custom memory alloc...
In other words, how does the implementation keeps track of the count?
Is there a map-like object maintained which is accessible by all the shared_ptr instances whose key is the pointer's address and value is the number of references? If I've to implement a shared_ptr, this is the first idea that's coming to my mind.
Is there a possibil...
I have a large number of name - value pairs (approx 100k) that I need to store in some sort of cache (say a hash map) where the value is a string with an average of about 30k bytes in size.
Now I know for a fact that a large number of the values have exactly the same string data. In order to avoid having to allocate the identical strin...
I have a chunk of memory, let us say 'NN'MB. I want a custom memory manager that will only allocate from this memory. The memory manager should be capable of allocating, freeing using the chunk already available. It will be great if it can also handle fragmentation.
Edited: I looking for some open source in C, or is there some API like...
I understood that in certain Windows XP programs, like Photoshop, there is something called "scratch disks". What I understood that this means, and please correct me if I'm wrong, is that Photoshop manages its own virtual memory on the hard-drive, instead of letting Windows manage it. I understood that the reason for this is some limitat...
Hi, I am dealing with a lot of strings in my program.
These string data don't change through out the whole life time after they being read into my program.
But since the C++ string reserves capacity, they waste a lot of space that won't be used for sure.
I tried to release those spaces, but it didn't work.
The following is the simple c...
I have created an accelerometer variable:
UIAccelerometer *objAccelerometer;
that I am associating to the sharedAccelerometer instance:
objAccelerometer = [UIAccelerometer sharedAccelerometer];
objAccelerometer.delegate = self;
When I release this view (to load a different view), the accelerometer instance causes the program to d...
For my understanding there are always two types of memory:
the working storage
the "disk space"
So when you have a 16 GB iPhone, does it have 16 GB of working storage? or 16 GB of "disk space"? Which "Memory" is Apple talking about in his Docs, when it comes to performance and memory management? It looks like the working storage, but...
In the terms of Apple's Documentation: What does "Memory Footprint" mean? How much Memory my App consumes? Does someone have a good explanation for that term?
...
Apple says that this is a good idea for saving memory. What would that look like in code?
...
Hello,
I've wanted to test if with multiply processes I'm able to use more than 4GB of ram on 32bit O.S (mine: Ubuntu with 1GB ram).
So I've written a small program that mallocs slightly less then 1GB, and do some action on that array, and ran 5 instances of this program vie forks.
The thing is, that I suspect that O.S killed 4 of them...
What's a good way to estimate the memory footprint of an object?
Conversely, what's a good way to measure the footprint?
For example, say I have a dictionary whose values are lists of integer,float tuples:
d['key'] = [ (1131, 3.11e18), (9813, 2.48e19), (4991, 9.11e18) ]
I have 4G of physical memory and would like to figure out appro...
I recently read the excellent article "The Transactional Memory / Garbage Collection Analogy" by Dan Grossman. One sentence really caught my attention:
In theory, garbage collection can
improve performance by increasing
spatial locality (due to
object-relocation), but in practice we
pay a moderate performance cost for
softw...
I have a web service I'm trying to use on one of my sites. When I call the web service (which is created in C#) I get an error on several lines where try to execute an SP, which was created as an assembly. This web service works on our development environment but not on live. Our live and dev environments run on the same server, but diff...
I need to programmatically find out exactly how much memory a given Java Object is occupying including the memory occupied by the objects that it is referencing.
I can generate a memory heap dump and analyse the results using a tool. However it takes a considerable amount of time to generate a heap dump and for such a tool to read the ...
I've devoted a large number of lines of C code to cleanup-labels/conditionals for failed memory allocation (indicated by the alloc family returning NULL). I was taught that this was a good practice so that, on memory failure, an appropriate error status could be flagged and the caller could potentially perform "graceful memory cleanup" a...
char *p = new char[200];
char *p1 = p;
char *p2 = &p[100];
delete [] p1;
Btw this is not a test or anything i actually need to know this :)
...
Hi,
this question is related to this one. Given this code
char *p = new char[200];
delete[] p;
what would happen if you set p[100] = '\0' before deleting p?
I had some code where I got a debug error when I tried to delete a not null-terminated char array, something about deleting heap memory that's not assigned. It seemed to delete ...
FreeBSD implements page coloring with
paging queues. The queues are arranged
according to the size of the
processor’s L1 and L2 caches; and when
a new page needs to be allocated,
FreeBSD tries to get one that is
optimally aligned for the cache.
Can somebody please explain the above lines, what is the concept of paging qu...