diff options
author | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
---|---|---|
committer | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
commit | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Wasabi/bfc/stack.cpp | |
parent | 537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff) | |
download | winamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz |
Initial community commit
Diffstat (limited to 'Src/Wasabi/bfc/stack.cpp')
-rw-r--r-- | Src/Wasabi/bfc/stack.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Src/Wasabi/bfc/stack.cpp b/Src/Wasabi/bfc/stack.cpp new file mode 100644 index 00000000..98199463 --- /dev/null +++ b/Src/Wasabi/bfc/stack.cpp @@ -0,0 +1,77 @@ +#include "precomp_wasabi_bfc.h" +#include "stack.h" + +//#define STACK_SIZE_INCREMENT 250 + +// going from 250 to 32 decreases size of VM working set by several megabytes +#define STACK_SIZE_INCREMENT 32 + +StackBase::StackBase() +{ + nslots = 0; + cur = 0; + stack = NULL; +} + +StackBase::~StackBase() +{ + if (stack != NULL) FREE(stack); +} + +int StackBase::push(void *item, int sizeofT, int increment) +{ + if (increment <= 0) increment = STACK_SIZE_INCREMENT; + if (stack == NULL) { + nslots = increment; + stack = (char*)MALLOC(sizeofT * nslots); + } else if (cur >= nslots) { + int newnslots = nslots + increment; + stack = (char*)REALLOC(stack, sizeofT*newnslots); + nslots = newnslots; + } + MEMCPY(stack + cur*sizeofT, item, sizeofT); + cur++; + return cur; +} + +int StackBase::peek() { + return cur; +} + +int StackBase::peekAt(void *ptr, int n, int sizeofT) { + if (ptr != NULL) MEMCPY(ptr, stack + (cur-1-n)*sizeofT, sizeofT); + return cur; +} + +int StackBase::getRef(void **ptr, int n, int sizeofT) { + if (ptr != NULL) *ptr = stack + (cur-1-n)*sizeofT; + return cur; +} + +void *StackBase::top(int sizeofT) { + ASSERT(cur >= 0); + if (cur == 0) return NULL; + return stack + (cur-1)*sizeofT; +} + +int StackBase::pop(void *ptr, int sizeofT) { + ASSERT(cur >= 0); + if (cur == 0) return 0; + ASSERT(stack != NULL); + --cur; + if (ptr != NULL) MEMCPY(ptr, stack + cur*sizeofT, sizeofT); + return 1; +} + +int StackBase::isempty() { + return cur == 0; +} + +void StackBase::purge() { + ASSERT(isempty()); + if (stack != NULL) { + FREE(stack); + stack = NULL; + } +} + |