Raised This Month: $ Target: $400
 0% 

CloneHandle


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 02-24-2010 , 03:56   CloneHandle
Reply With Quote #1

The purpose of this native is to create a copy of the data in the given handle, right?

So if I do:

Code:
new Handle:test = CreateArray(32);
    PushArrayString(test, "hello");
    PushArrayString(test, "hello2");
    PushArrayString(test, "hello3");
    new Handle:test2 = CloneHandle(test);
    SetArrayString(test2, 0, "hi");
    
    decl String:test3[32];
    GetArrayString(test, 0, test3, 32);
    PrintToServer("%s", test3);
Index 0 in the first array should print "hello" while index 0 in the second array should print "hi."


Well, this actually prints "hi." Modifying the data of the cloned handle modifies the data of the handle it was cloned from. If this is how it's meant to be, then how would I go about creating an independent clone?
__________________
Greyscale is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 02-24-2010 , 04:29   Re: CloneHandle
Reply With Quote #2

No, it's to make a new reference counted handle. The resource it represents will not be destroyed until the count is zero. If you get a handle from another plugin and want to store it, you must clone it. Otherwise, the other plugin could close the handle and you would not know; later use of your "copy" will end up erroring.
Fyren is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 02-24-2010 , 08:54   Re: CloneHandle
Reply With Quote #3

Quote:
Originally Posted by Greyscale View Post
If this is how it's meant to be, then how would I go about creating an independent clone?
From adt_array.inc:

PHP Code:
/**
 * Clones an array, returning a new handle with the same size and data. This should NOT
 * be confused with CloneHandle. This is a completely new handle with the same data but
 * no relation to the original. You MUST close it.
 *
 * @param array            Array handle to be cloned
 * @return                New handle to the cloned array object
 * @error                Invalid Handle
 */
native Handle:CloneArray(Handle:array); 
__________________
plop
p3tsin is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 02-24-2010 , 18:24   Re: CloneHandle
Reply With Quote #4

Fyren: I understand now, thank you.

p3tsin: *facepalm* Thank you as well.
__________________
Greyscale is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode