How to reduce the memory used in general ?
In general you have to use algorithm that is not using so much memory
try not to initialize huge arrays within loops, free them when not needed, use global arrays,variables, reduce use of arrays etc and as always use better algorithms
Use STL Vectors instead of Arrays.A lot of memory can be saved using vectors.
- when dealing with various problems generally their is a fight between time and memory usage.Algorithm deals with this memory-time trade. so to reduce memory usage, find a different algo. best example is quick sort vs merge sort .
- prior knowledge of STL container would be helpful.
As @betlista mentioned, most important way to reduce memory usage is to use algorithm which requires less memory. Think asymptotically.
Another fact I discovered- For same program iostream for Input/Output uses more memory than stdio. The difference is small - 2.8M vs 2.6M, but still worth noting.
I agree, especially in Java object contruction (new) is very slow, so usage of “global” array is better, but this tip is for speed and not memory O:-)
the tag is a runtime error… probably a SIGSEGV… and this should probably fix that