mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 06:44: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 cannot be copied around within RAM
|
||||
// - 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
|
||||
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_freeBucket(Toy_Bucket** bucketHandle);
|
||||
|
||||
//some useful sizes, could be swapped out as needed
|
||||
#ifndef TOY_BUCKET_TINY
|
||||
#define TOY_BUCKET_TINY (1024 * 2)
|
||||
//standard capacity sizes
|
||||
#ifndef TOY_BUCKET_1KB
|
||||
#define TOY_BUCKET_1KB (1 << 10)
|
||||
#endif
|
||||
|
||||
#ifndef TOY_BUCKET_SMALL
|
||||
#define TOY_BUCKET_SMALL (1024 * 4)
|
||||
#ifndef TOY_BUCKET_2KB
|
||||
#define TOY_BUCKET_2KB (1 << 11)
|
||||
#endif
|
||||
|
||||
#ifndef TOY_BUCKET_MEDIUM
|
||||
#define TOY_BUCKET_MEDIUM (1024 * 8)
|
||||
#ifndef TOY_BUCKET_4KB
|
||||
#define TOY_BUCKET_4KB (1 << 12)
|
||||
#endif
|
||||
|
||||
#ifndef TOY_BUCKET_LARGE
|
||||
#define TOY_BUCKET_LARGE (1024 * 16)
|
||||
#ifndef TOY_BUCKET_8KB
|
||||
#define TOY_BUCKET_8KB (1 << 13)
|
||||
#endif
|
||||
|
||||
#ifndef TOY_BUCKET_HUGE
|
||||
#define TOY_BUCKET_HUGE (1024 * 32)
|
||||
#ifndef TOY_BUCKET_16KB
|
||||
#define TOY_BUCKET_16KB (1 << 14)
|
||||
#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
|
||||
#define TOY_BUCKET_IDEAL (TOY_BUCKET_HUGE - sizeof(Toy_Bucket))
|
||||
#define TOY_BUCKET_IDEAL (TOY_BUCKET_64KB - sizeof(Toy_Bucket))
|
||||
#endif
|
||||
|
||||
|
||||
@@ -960,7 +960,7 @@ void Toy_bindVMToModule(Toy_VM* vm, unsigned char* module) {
|
||||
vm->stringBucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||
}
|
||||
if (vm->scopeBucket == NULL) {
|
||||
vm->scopeBucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
||||
vm->scopeBucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||
}
|
||||
if (vm->stack == NULL) {
|
||||
vm->stack = Toy_allocateStack();
|
||||
|
||||
@@ -51,7 +51,7 @@ int test_value_creation(void) {
|
||||
//test creating strings
|
||||
{
|
||||
//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!"));
|
||||
|
||||
@@ -116,7 +116,7 @@ int test_value_copying(void) {
|
||||
//test string copy
|
||||
{
|
||||
//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 result = Toy_copyValue(original);
|
||||
@@ -240,7 +240,7 @@ int test_value_equality(void) {
|
||||
//again with strings
|
||||
{
|
||||
//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 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
|
||||
{
|
||||
//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 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
|
||||
{
|
||||
//setup
|
||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||
Toy_Value value = TOY_VALUE_FROM_NULL();
|
||||
|
||||
//run
|
||||
@@ -387,7 +387,7 @@ int test_value_stringify(void) {
|
||||
//stringify boolean (true)
|
||||
{
|
||||
//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);
|
||||
|
||||
//run
|
||||
@@ -413,7 +413,7 @@ int test_value_stringify(void) {
|
||||
//stringify boolean (false)
|
||||
{
|
||||
//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);
|
||||
|
||||
//run
|
||||
@@ -439,7 +439,7 @@ int test_value_stringify(void) {
|
||||
//stringify integer
|
||||
{
|
||||
//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);
|
||||
|
||||
//run
|
||||
@@ -465,7 +465,7 @@ int test_value_stringify(void) {
|
||||
//stringify float
|
||||
{
|
||||
//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);
|
||||
|
||||
//run
|
||||
@@ -491,7 +491,7 @@ int test_value_stringify(void) {
|
||||
//stringify strings
|
||||
{
|
||||
//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_String* string = Toy_stringifyValue(&bucket, value);
|
||||
@@ -513,7 +513,7 @@ int test_value_stringify(void) {
|
||||
//stringify array
|
||||
{
|
||||
//setup
|
||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_SMALL);
|
||||
Toy_Bucket* bucket = Toy_allocateBucket(TOY_BUCKET_IDEAL);
|
||||
|
||||
//setup
|
||||
Toy_Array* array = Toy_resizeArray(NULL, TOY_ARRAY_INITIAL_CAPACITY);
|
||||
|
||||
Reference in New Issue
Block a user