Next: 18.4.3 Some statistics collected
Up: 18.4 Memory Debugging
Previous: 18.4.1 Using dmalloc
18.4.2 Memory Conservation Tips
Some tips to saving memory (some of these use examples from the
cmcast-100.tcl script):
If you have many links or nodes:
- Avoid trace-all :
- $ns trace-all $f causes trace objects to be pushed on all links. If
you only want to trace one link, there's no need for this overhead. Saving
is about 14 KB/link.
- Use arrays for sequences of variables :
- Each variable, say n$i in set n$i [$ns node], has a certain
overhead. If a sequence of nodes are created as an array, i.e.
n($i), then only one variable is created, consuming much less
memory. Saving is about 40+ Byte/variable.
- Avoid unnecessary variables :
- If an object will not be referred to later on, avoid naming the object.
E.g.
set cmcast(1) [new CtrMcast $ns $n(1) $ctrmcastcomp [list 1 1]]
would be better if replaced by
new CtrMcast $ns $n(1) $ctrmcastcomp [list 1 1].
Saving is about 80 Byte/variable.
- Run on top of FreeBSD :
- malloc() overhead on FreeBSD is less than on some other systems. We will
eventually port that allocator to other platofrms.
- Dynamic binding (NEW) :
- Using bind() in C++ consumes memory for each object you create. This
approach can be very expensive if you create many identical objects.
Changing bind() to delay_bind() changes this memory
requirement to per-class. See /object.cc for an example of how to do
binding, either way.
Next: 18.4.3 Some statistics collected
Up: 18.4 Memory Debugging
Previous: 18.4.1 Using dmalloc
2000-08-24