There appears to be several ways to create constant strings.
MAKE_CONSTANT_SHARED_STRING make_shared_binary_string make_shared_string
What are the practical differences?
Only one of them create constant strings.
/ Per Hedbor ()
Previous text:
2003-01-12 18:44: Subject: Making strings
There appears to be several ways to create constant strings.
MAKE_CONSTANT_SHARED_STRING make_shared_binary_string make_shared_string
What are the practical differences?
/ Martin Nilsson (Åskblod)
No, not really.
Let me elaborate:
MAKE_CONSTANT_SHARED_STRING() expands to something along these lines:
static struct pike_string *_whatever; struct pike_string *x; if( !_whatever ) whatever=create_shared_binary_string(#X,sizeof(#X)-sizeof("")); x = _whatever; add_ref( x );
Then you call free_string() when you are done with it, but note that one reference is kept in the _whatever static variable. If pike is compiled with debug, it is also added to a list of strings that are free:d when pike exists, thus avoiding memory leaks.
make_shared*_string creates a string, without the extra code.
make_shared_string in the pike_module_init function or similar initialization method is better than MAKE_CONSTANT_SHARED_STRING speed-wise, but can be somewhat harder to read at times, and there is no lazy allocation.
/ Per Hedbor ()
Previous text:
2003-01-12 18:52: Subject: Making strings
So it would be benefitial if all strings allocated during module initialization was created with MAKE_CONSTANT_SHARED_STRING?
/ Martin Nilsson (Åskblod)
The difference between make_shared_binary_string and make_shared_string is obvious enough, I think. The difference between MAKE_CONSTANT_SHARED_STRING and the others is that it takes a string literal (which might contain \0), and that it doesn't redo the string allocation/hashing work if it's executed more than once.
/ Martin Stjernholm, Roxen IS
Previous text:
2003-01-12 18:44: Subject: Making strings
There appears to be several ways to create constant strings.
MAKE_CONSTANT_SHARED_STRING make_shared_binary_string make_shared_string
What are the practical differences?
/ Martin Nilsson (Åskblod)
pike-devel@lists.lysator.liu.se