I've written a simple socket-server app that securities (stock
market shares) data and allows clients to query over them. The
app starts by loading instrument information from a CSV file into
some structs, then listens on a socket responding to queries. It
doesn't mutate the data or allocate anything substantial.

There are 2 main structs in the app. One stores security data,
and the other groups together securities. They are defined as
follows :

````
__gshared Securities securities;

struct Security
{
          string RIC;
          string TRBC;
          string[string] fields;
          double[string] doubles;

          @nogc @property pure size_t bytes()
          {
              size_t bytes;

              bytes = RIC.sizeof + RIC.length;
              bytes += TRBC.sizeof + TRBC.length;

              foreach(k,v; fields) {
                  bytes += (k.sizeof + k.length + v.sizeof +
v.length);
              }

              foreach(k, v; doubles) {
                  bytes += (k.sizeof + k.length + v.sizeof);
              }

              return bytes + Security.sizeof;
          }
}

struct Securities
{
          Security[] securities;
          private size_t[string] rics;

          // Store offsets for each TRBC group
          ulong[2][string] econSect;
          ulong[2][string] busSect;
          ulong[2][string] IndGrp;
          ulong[2][string] Ind;

          @nogc @property pure size_t bytes()
          {
              size_t bytes;

              foreach(Security s; securities) {
                  bytes += s.sizeof + s.bytes;
              }

              foreach(k, v; rics) {
                  bytes += k.sizeof + k.length + v.sizeof;
              }

              foreach(k, v; econSect) {
                  bytes += k.sizeof + k.length + v.sizeof;
              }

              foreach(k, v; busSect) {
                  bytes += k.sizeof + k.length + v.sizeof;
              }

              foreach(k, v; IndGrp) {
                  bytes += k.sizeof + k.length + v.sizeof;
              }

              foreach(k, v; Ind) {
                  bytes += k.sizeof + k.length + v.sizeof;
              }

              return bytes + Securities.sizeof;
          }
}
````

Calling Securities.bytes shows "188 MB", but "ps" shows about 591
MB of Resident memory. Where is the memory usage coming from?
What am i missing?

Reply via email to