RE: [PHP-DEV] when to duplicate string using add_index_string?
| From: | Marc Boeren | Date: | Thu, 08 Feb 2001 16:20:45 +0000 |
| Subject: | RE: [PHP-DEV] when to duplicate string using add_index_string? | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-46036@lists.php.net to get a copy of this message | ||
>'duplicate' does mean 'duplicate me'.
>If duplicate is set to 0, then you tell the engine not to duplicate the
>string, but use it as-is. If it's set to 1, then you tell the engine to
>duplicate it, because this string is either static, or already referenced
>by other things in PHP.
Now I'm confused... :-)
What happens if I actually _want_ to reference the same string?
Say, I get some string from somewhere (say, an argument), then I should use
1 for duplicate, because it is already referenced...
like this:
add_index_string(return_value, 0, arg->value.str.val, 1); // $data[0] ==
'*arg->value.str.val'
Then, when I need to create the association (pointing to the same data), I
should use 0, because I don't want the data duplicated...
like this
add_assoc_string(return_value, "zero", arg->value.str.val, 0); //
$data["zero"] == $data[0] == '*arg->value.str.val'
This sequence is actually what I said in my first example, so do I still not
get it, or was my first example not clear enough?
What I didn't say in my first example is that I don't allocate the data
myself...
BTW, if I did allocate the data myself, and used a 0 in the first call,
should I still deallocate the data, or is this handled by the engine now?
And if I _do_ use a 1 (so it gets duplicated) then I certainly must
deallocate the date myself, right?
Cheerio, Marc.