BwTree icon indicating copy to clipboard operation
BwTree copied to clipboard

object uses a lot of stack

Open roblatham00 opened this issue 8 years ago • 0 comments

More of a documentation thing than an issue, I guess, but I spent a lot of time trying to figure out why declaring a new BwTree object on the stack was causing my little test program to coredump. Hope writing up this issue saves someone else a bit of trouble.

Declaring the tree on the heap has no such surprises.

Simple little program to demonstrate:

#include <bwtree.h>
void declare_on_heap() {
    auto *t  = new wangziqi2013::bwtree::BwTree<int, int>;
    printf("HEAP OK\n");
}

void declare_on_stack() {
  wangziqi2013::bwtree::BwTree<int, int> t;
  printf("STACK OK\n");
}

int main(void)
{
    declare_on_heap();
    declare_on_stack();
}

compiling little test with -Wstack-usage=262144 the compiler reports

warning: stack usage might be 16782800 bytes

and you can observe the dynamic allocation succeeding but not the stack-allocated one.

roblatham00 avatar Sep 18 '17 17:09 roblatham00