-
Notifications
You must be signed in to change notification settings - Fork 79
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
change unnecessary heap allocs to stack allocs #24
Conversation
@rweichler can you explain what difference this makes? I'm interested in reducing processing overhead as much as possible but coming from the scripting side of things I'm not as up to speed with memory management as I'd like to be. |
@ephemer Sure. The basic idea is that in most modern operating systems, there's 2 places to allocate memory. On the stack and on the heap. Stack is temporary stuff and heap is more permanent stuff. The stack basically works like this: int x;
if(true) {
int y;
if(true) {
int z;
}
}
some_function(x); So what the OS does is this:
Since all of that static scoping stuff can be figured out by the compiler it ends up being way more efficient since you're just pushing and popping stuff from a stack. On the contrary, with So back to my changes, the thing I noticed is that he freed the pointers as soon as the function exited, so there was no need to put it in the heap since they were going to go away as soon as the function ended anyway. |
Thank you for this and sorry for the late reply, I was travelling in Canada
|
@rweichler thanks for the awesome explanation, that makes sense in terms of the function call stack in JavaScript, for example. Awesome stuff |
Change unnecessary heap allocs to stack allocs
@rweichler @bartolsthoorn Just implemented this commit for a filterbank we made in NVDSP and got about a 15% reduction in CPU usage. Great stuff. |
should help with overhead.