How to reduce the memory used in general ?

How to reduce the memory used in general ?

In general you have to use algorithm that is not using so much memory :smiley:

4 Likes

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 :slight_smile:

1 Like

Use STL Vectors instead of Arrays.A lot of memory can be saved using vectors.

2 Likes
  1. 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 .
  2. prior knowledge of STL container would be helpful.
2 Likes

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.

1 Like

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:-)

1 Like

the tag is a runtime error… probably a SIGSEGV… and this should probably fix that :slight_smile: