mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Tweaked standard bucket sizes, see #160
Hyacinth: It's pronounced "Bouquet"!
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
// - It can only expand until it is freed
|
// - It can only expand until it is freed
|
||||||
// - It cannot be copied around within RAM
|
// - It cannot be copied around within RAM
|
||||||
// - It cannot allocate more memory than it has capacity
|
// - It cannot allocate more memory than it has capacity
|
||||||
// If each of these rules are followed, the bucket is actually more efficient than any other option
|
// If each of these rules are followed, this is actually more efficient than other options
|
||||||
|
|
||||||
//a custom allocator
|
//a custom allocator
|
||||||
typedef struct Toy_Bucket { //32 | 64 BITNESS
|
typedef struct Toy_Bucket { //32 | 64 BITNESS
|
||||||
@@ -20,27 +20,37 @@ TOY_API Toy_Bucket* Toy_allocateBucket(unsigned int capacity);
|
|||||||
TOY_API void* Toy_partitionBucket(Toy_Bucket** bucketHandle, unsigned int amount);
|
TOY_API void* Toy_partitionBucket(Toy_Bucket** bucketHandle, unsigned int amount);
|
||||||
TOY_API void Toy_freeBucket(Toy_Bucket** bucketHandle);
|
TOY_API void Toy_freeBucket(Toy_Bucket** bucketHandle);
|
||||||
|
|
||||||
//some useful sizes, could be swapped out as needed
|
//standard capacity sizes
|
||||||
#ifndef TOY_BUCKET_TINY
|
#ifndef TOY_BUCKET_1KB
|
||||||
#define TOY_BUCKET_TINY (1024 * 2)
|
#define TOY_BUCKET_1KB (1 << 10)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TOY_BUCKET_SMALL
|
#ifndef TOY_BUCKET_2KB
|
||||||
#define TOY_BUCKET_SMALL (1024 * 4)
|
#define TOY_BUCKET_2KB (1 << 11)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TOY_BUCKET_MEDIUM
|
#ifndef TOY_BUCKET_4KB
|
||||||
#define TOY_BUCKET_MEDIUM (1024 * 8)
|
#define TOY_BUCKET_4KB (1 << 12)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TOY_BUCKET_LARGE
|
#ifndef TOY_BUCKET_8KB
|
||||||
#define TOY_BUCKET_LARGE (1024 * 16)
|
#define TOY_BUCKET_8KB (1 << 13)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TOY_BUCKET_HUGE
|
#ifndef TOY_BUCKET_16KB
|
||||||
#define TOY_BUCKET_HUGE (1024 * 32)
|
#define TOY_BUCKET_16KB (1 << 14)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef TOY_BUCKET_32KB
|
||||||
|
#define TOY_BUCKET_32KB (1 << 15)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef TOY_BUCKET_64KB
|
||||||
|
#define TOY_BUCKET_64KB (1 << 16)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//CPU L1 caches tend to be 64kb, but that's far from guaranteed
|
||||||
#ifndef TOY_BUCKET_IDEAL
|
#ifndef TOY_BUCKET_IDEAL
|
||||||
#define TOY_BUCKET_IDEAL (TOY_BUCKET_HUGE - sizeof(Toy_Bucket))
|
#define TOY_BUCKET_IDEAL (TOY_BUCKET_64KB - sizeof(Toy_Bucket))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -960,7 +960,7 @@ void Toy_bindVMToModule(Toy_VM* vm, unsigned char* module) {
|
|||||||
vm->stringBucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
vm->stringBucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||||
}
|
}
|
||||||
if (vm->scopeBucket == NULL) {
|
if (vm->scopeBucket == NULL) {
|
||||||
vm->scopeBucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
vm->scopeBucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||||
}
|
}
|
||||||
if (vm->stack == NULL) {
|
if (vm->stack == NULL) {
|
||||||
vm->stack = Toy_allocateStack();
|
vm->stack = Toy_allocateStack();
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ int test_value_creation(void) {
|
|||||||
//test creating strings
|
//test creating strings
|
||||||
{
|
{
|
||||||
//setup
|
//setup
|
||||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||||
|
|
||||||
Toy_Value greeting = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "Hello world!"));
|
Toy_Value greeting = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "Hello world!"));
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ int test_value_copying(void) {
|
|||||||
//test string copy
|
//test string copy
|
||||||
{
|
{
|
||||||
//setup
|
//setup
|
||||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||||
|
|
||||||
Toy_Value original = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "Hello world!"));
|
Toy_Value original = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "Hello world!"));
|
||||||
Toy_Value result = Toy_copyValue(original);
|
Toy_Value result = Toy_copyValue(original);
|
||||||
@@ -240,7 +240,7 @@ int test_value_equality(void) {
|
|||||||
//again with strings
|
//again with strings
|
||||||
{
|
{
|
||||||
//setup
|
//setup
|
||||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||||
|
|
||||||
Toy_Value answer = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "poe wrote on both"));
|
Toy_Value answer = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "poe wrote on both"));
|
||||||
Toy_Value question = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "why is a raven like a writing desk?"));
|
Toy_Value question = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "why is a raven like a writing desk?"));
|
||||||
@@ -332,7 +332,7 @@ int test_value_comparison(void) {
|
|||||||
//again with strings
|
//again with strings
|
||||||
{
|
{
|
||||||
//setup
|
//setup
|
||||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||||
|
|
||||||
Toy_Value answer = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "poe wrote on both"));
|
Toy_Value answer = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "poe wrote on both"));
|
||||||
Toy_Value question = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "why is a raven like a writing desk?"));
|
Toy_Value question = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "why is a raven like a writing desk?"));
|
||||||
@@ -361,7 +361,7 @@ int test_value_stringify(void) {
|
|||||||
//stringify null
|
//stringify null
|
||||||
{
|
{
|
||||||
//setup
|
//setup
|
||||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||||
Toy_Value value = TOY_VALUE_FROM_NULL();
|
Toy_Value value = TOY_VALUE_FROM_NULL();
|
||||||
|
|
||||||
//run
|
//run
|
||||||
@@ -387,7 +387,7 @@ int test_value_stringify(void) {
|
|||||||
//stringify boolean (true)
|
//stringify boolean (true)
|
||||||
{
|
{
|
||||||
//setup
|
//setup
|
||||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||||
Toy_Value value = TOY_VALUE_FROM_BOOLEAN(true);
|
Toy_Value value = TOY_VALUE_FROM_BOOLEAN(true);
|
||||||
|
|
||||||
//run
|
//run
|
||||||
@@ -413,7 +413,7 @@ int test_value_stringify(void) {
|
|||||||
//stringify boolean (false)
|
//stringify boolean (false)
|
||||||
{
|
{
|
||||||
//setup
|
//setup
|
||||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||||
Toy_Value value = TOY_VALUE_FROM_BOOLEAN(false);
|
Toy_Value value = TOY_VALUE_FROM_BOOLEAN(false);
|
||||||
|
|
||||||
//run
|
//run
|
||||||
@@ -439,7 +439,7 @@ int test_value_stringify(void) {
|
|||||||
//stringify integer
|
//stringify integer
|
||||||
{
|
{
|
||||||
//setup
|
//setup
|
||||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||||
Toy_Value value = TOY_VALUE_FROM_INTEGER(42);
|
Toy_Value value = TOY_VALUE_FROM_INTEGER(42);
|
||||||
|
|
||||||
//run
|
//run
|
||||||
@@ -465,7 +465,7 @@ int test_value_stringify(void) {
|
|||||||
//stringify float
|
//stringify float
|
||||||
{
|
{
|
||||||
//setup
|
//setup
|
||||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||||
Toy_Value value = TOY_VALUE_FROM_FLOAT(3.1415f);
|
Toy_Value value = TOY_VALUE_FROM_FLOAT(3.1415f);
|
||||||
|
|
||||||
//run
|
//run
|
||||||
@@ -491,7 +491,7 @@ int test_value_stringify(void) {
|
|||||||
//stringify strings
|
//stringify strings
|
||||||
{
|
{
|
||||||
//setup
|
//setup
|
||||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||||
|
|
||||||
Toy_Value value = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "Hello world!"));
|
Toy_Value value = TOY_VALUE_FROM_STRING(Toy_createString(&bucket, "Hello world!"));
|
||||||
Toy_String* string = Toy_stringifyValue(&bucket, value);
|
Toy_String* string = Toy_stringifyValue(&bucket, value);
|
||||||
@@ -513,7 +513,7 @@ int test_value_stringify(void) {
|
|||||||
//stringify array
|
//stringify array
|
||||||
{
|
{
|
||||||
//setup
|
//setup
|
||||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||||
|
|
||||||
//setup
|
//setup
|
||||||
Toy_Array* array = Toy_resizeArray(NULL, TOY_ARRAY_INITIAL_CAPACITY);
|
Toy_Array* array = Toy_resizeArray(NULL, TOY_ARRAY_INITIAL_CAPACITY);
|
||||||
|
|||||||
Reference in New Issue
Block a user