# HG changeset patch # User Paul Boddie # Date 1548706616 -3600 # Node ID f84970ad40409b3df51f5b31170193c91911df35 # Parent 31053f0bb63b0acfe9179b7c1e1babc976836629 Test performance with the allocation of opaque blocks containing many instances. This improves performance considerably, but the float instances are never reclaimed. Finding a way to expose the instances as they are issued would make this approach sustainable. diff -r 31053f0bb63b -r f84970ad4040 templates/native/float.c --- a/templates/native/float.c Sun Jan 27 14:11:25 2019 +0100 +++ b/templates/native/float.c Mon Jan 28 21:16:56 2019 +0100 @@ -30,26 +30,16 @@ /* A table of preallocated float instances. */ -#define NUM_PREALLOCATED 1000 +#define NUM_PREALLOCATED 10000 -__ref preallocated_floats[NUM_PREALLOCATED]; - +static __ref preallocated_floats; static int floats_left = 0; /* Preallocate some float instances. */ static void preallocate_floats() { - int i; - - for (i = 0; i < NUM_PREALLOCATED; i++) - { - /* Allocate a float for each table entry. */ - - preallocated_floats[i] = \ - __ALLOCATEIM(1, __INSTANCESIZE(__builtins___float_float)); - } - + preallocated_floats = __ALLOCATEIM(NUM_PREALLOCATED, __INSTANCESIZE(__builtins___float_float)); floats_left = NUM_PREALLOCATED; } @@ -62,7 +52,7 @@ preallocate_floats(); floats_left--; - obj = preallocated_floats[floats_left]; + obj = preallocated_floats; /* Initialise the instance. */ @@ -74,6 +64,10 @@ attr = __ATTRVALUE(obj); __set_trailing_data(attr, __builtins___float_float, n); + /* Reference the next float. */ + + preallocated_floats = (__ref) ((char *) preallocated_floats + __INSTANCESIZE(__builtins___float_float)); + return attr; }