mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Reworked generic structures, read more
The following structures are now more independant: - Toy_Array - Toy_Stack - Toy_Bucket - Toy_String I reworked a lot of the memory allocation, so now there are more direct calls to malloc() or realloc(), rather than relying on the macros from toy_memory.h. I've also split toy_memory into proper array and bucket files, because it makes more sense this way, rather than having them both jammed into one file. This means the eventual hashtable structure can also stand on its own. Toy_Array is a new wrapper around raw array pointers, and all of the structures have their metadata embedded into their allocated memory now, using variable length array members. A lot of 'capacity' and 'count' variables were changed to 'size_t' types, but this doesn't seem to be a problem anywhere. If the workflow fails, then I'll leave it for tonight - I'm too tired, and I don't want to overdo myself.
This commit is contained in:
@@ -3,16 +3,15 @@
|
||||
#include "toy_common.h"
|
||||
#include "toy_value.h"
|
||||
|
||||
typedef struct Toy_Stack {
|
||||
Toy_Value* ptr;
|
||||
int capacity;
|
||||
int count;
|
||||
} Toy_Stack;
|
||||
typedef struct Toy_Stack { //32 | 64 BITNESS
|
||||
size_t capacity; //4 | 4
|
||||
size_t count; //4 | 4
|
||||
char data[]; //- | -
|
||||
} Toy_Stack; //8 | 8
|
||||
|
||||
TOY_API void Toy_initStack(Toy_Stack* stack); //null memory
|
||||
TOY_API void Toy_preallocateStack(Toy_Stack* stack); //non-null memory, ready to go
|
||||
TOY_API Toy_Stack* Toy_allocateStack();
|
||||
TOY_API void Toy_freeStack(Toy_Stack* stack);
|
||||
|
||||
TOY_API void Toy_pushStack(Toy_Stack* stack, Toy_Value value);
|
||||
TOY_API Toy_Value Toy_peekStack(Toy_Stack* stack);
|
||||
TOY_API Toy_Value Toy_popStack(Toy_Stack* stack);
|
||||
TOY_API void Toy_pushStack(Toy_Stack** stack, Toy_Value value);
|
||||
TOY_API Toy_Value Toy_peekStack(Toy_Stack** stack);
|
||||
TOY_API Toy_Value Toy_popStack(Toy_Stack** stack);
|
||||
|
||||
Reference in New Issue
Block a user