sp_setstring by value

19 views
Skip to first unread message

Evgeny M.

unread,
Jan 30, 2016, 5:27:20 PM1/30/16
to Sophia database
Is there a way to call sp_setstring and copy variable, not just the pointer? Because if I need to assign a properyt in a function, I get this:

static void set_prop(void* o, const char* name) {
    int r = rand();
    sp_setstring(o, name, &r, sizeof(r));
}

void *o = sp_document(db);
int size;
set_prop(o, "key"); 
printf("key == %i\r\n", *(int*)sp_getstring(o, "key", &size));
set_prop(o, "value");
printf("value == %i\r\n", *(int*)sp_getstring(o, "value", &size));
printf("key == %i\r\n", *(int*)sp_getstring(o, "key", &size)); //key is now actually not what it used to be


Output:
key == 1804289383
value == 846930886
key == 846930886 

Dmitry Simonenko

unread,
Jan 31, 2016, 12:58:28 PM1/31/16
to Sophia database
Right now no, sorry.  That was intentional. Pointers passing were made due to performance reason, to reduce number of a memory allocatations.
Reply all
Reply to author
Forward
0 new messages