memory-optimization

Clean vector every loop iteration. What is the most memory efficient way?

Hi, I have a question about the std::vector. I have a very memory intensive algorithm where I forsee that predicting vector sizes and reserving enough memory for the vectors in advance will help me a lot with reducing memory usage. Which of the following is better: for ( ... ) { std::vector<Type> my_vector; my_vector.reserve(stuff...

Automated field re-ordering in C structs to avoid padding

I've spent a few minutes manually re-ordering fields in a struct in order to reduce padding effects[1], which feels like a few minutes too much. My gut feeling says that my time could probably be better spent writing up a Perl script or whatnot to do this kind of optimization for me. My question is whether this too is redundant; is the...

C++ Memory Efficient Solution for Ax=b Linear Algebra System

I am using Numeric Library Bindings for Boost UBlas to solve a simple linear system. The following works fine, except it is limited to handling matrices A(m x m) for relatively small 'm'. In practice I have a much larger matrix with dimension m= 10^6 (up to 10^7). Is there existing C++ approach for solving Ax=b that uses memory efficien...

Reducing memory usage of .NET applications?

I was wondering if anyone had any tips to reduce the memory usage of .NET applications. Consider the following simple C# program: class Program { static void Main(string[] args) { Console.ReadLine(); } } Compiled in release mode for x64 and running outside visual studio, the task manager reports the following: Wor...

PHP Memory Optimization

I am using xdebug to trace some code to see how much memory it is using, but at the start of the trace, it is using around 560224 bytes of memory. Is this normal? This is before any code is executed. Edit: I should have clarified; this is not what I am trying to optimize. I just noticed it and wanted an explanation. ...

Permutations of Varying Size

I'm trying to write a function in PHP that gets all permutations of all possible sizes. I think an example would be the best way to start off: $my_array = array(1,1,2,3); Possible permutations of varying size: 1 1 // * See Note 2 3 1,1 1,2 1,3 // And so forth, for all the sets of size 2 1,1,2 1,1,3 1,2,1 // And so forth, for all the...

Disk-based trie?

I'm trying to build a Trie but on a mobile phone which has very limited memory capacity. I figured that it is probably best that the whole structure be stored on disk, and only loaded as necessary since I can tolerate a few disk reads. But, after a few attempts, it seems like this is a very complicated thing to do. What are some ways t...

Memory efficient int-int dict in Python

Hi, I need a memory efficient int-int dict in Python that would support the following operations in O(log n) time: d[k] = v # replace if present v = d[k] # None or a negative number if not present I need to hold ~250M pairs, so it really has to be tight. Do you happen to know a suitable implementation (Python 2.7)? EDIT Removed i...