Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object uses a lot of stack #65

Open
roblatham00 opened this issue Sep 18, 2017 · 0 comments
Open

object uses a lot of stack #65

roblatham00 opened this issue Sep 18, 2017 · 0 comments

Comments

@roblatham00
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant