hello all.

I have a class member function that essentially looks like this:

ThisNode* _InsertAllBut(int value) {
    ThisNode* node = MallocAllocator.allocate!(ThisNode)(1);
    node.value = value;
    node_count++;
    return node;
}


I compile it on x86_64 and the compiler inserts a gc allocation.

I decompiled it, and it looks like it does this:

  ThisNode* _InsertAllBut(int value) {
      struct Thing {
          typeof(this) thing1;
          ThisNode* thing2;
          int thing3;
      }
      Thing* rbp28 = _d_allocmemory(0x14);
      rbp28.thing1 = this;
      rbp28.thing3 = value;
      if (this == 0) {
// not wasting my time figuring out _d_assert_msg's calling conventions
          r8d = 0x137c;
          rcx = something pointing to "src/multi_index.d";
          rdi = {length associated with rsi};
          rsi = something pointing to "null this";
          rdx = {length associated with rcx};
          _d_assert_msg();
      }
      invariant._d_invariant(this);
      rbp28.thing2 = MallocAllocator.allocate(1);
      rbp28.thing2.value = rbp28.thing3;
      this.nodecount ++;
      return rbp28.thing2;
  }


So. Why the heck is it using heap space for stack space? How the heck am I supposed to call this from within a destructor?

Reply via email to