ios - Shared instance of c file in objective c? -


i working on chess engine in c/objective-c , rewrote large part of engine in straight-c improve speed. question is, have 3kb of tables initialize in c file don't want reinitialize every time function file called. if regular objective-c class create shared instance. however, core of engine in 2 .h , .c files. should make of tables used engine static? persist between multiple other files calling functions in engine? should make static struct hold tables? i'm not sure best approach here. thanks!

example:

test.h:

int getint(int index); 

test.c:

static int integers[4] = {1,2,3,4}; int getint(int index) { return integers[index]; } 

every time call getint file, reallocate 'integers'? or reuse same array? want prevent unnecessarily reallocating bunch of static arrays.

ok, did accessor on static variable...

a static initialized once, initialized once per launch. can keep way, or change global access without calling function.

this code typically inlined, changing global more matter of taste performances.

edit: short summary on allocations  static int array[] = {1, 2}; // allocated , initialized once int array2[] = {1, 2, 3}; // allocated , initialized once  int function() {  int array3[] = {1, 2, 3}; // allocated , initialized @ every call of function();  static int *array4 = malloc(42); // allocated , initialized once  int *toto = malloc(42); // allocated @ every call of function(); } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -