Parameter (string * key)
Posted: 14 May 2013, 03:49
Many functions using the parameter (string * key). This parameter point is need to delete or do not need ,
the API documentation did not specify.
for example:(SimpleChat)
i saw code.i see here stdZoneName and stdZoneName is delete in ~LoginRequest()
but use SFSObject,for example
What I mean is a function best to state those pointers need to manage, which is not required。
This is my understanding, do not know right, if the use of the wrong, it will cause memory leaks。
(String * key) as a parameter, and is very troublesome to use。
for example:
way1:
way2:
but use other ClientAPI(like ObjectC)
Very simple!!!
if Modify
or
then can use
so simple too.
the API documentation did not specify.
for example:(SimpleChat)
Code: Select all
CT2CA pszConvertedAnsiString (username);
std::string* stdUsername = new string(pszConvertedAnsiString);
// Programmatically set the zone name
std::string* stdZoneName = new string("BasicExamples");
// Perform login request
LoginRequest* request = new LoginRequest(stdUsername, NULL, stdZoneName);
ptrMainFrame->m_ptrSmartFox->Send(request);
delete request;
request = NULL;i saw code.i see here stdZoneName and stdZoneName is delete in ~LoginRequest()
Code: Select all
LoginRequest::~LoginRequest()
{
delete zoneName;
zoneName = NULL;
delete userName;
userName = NULL;
delete password;
password = NULL;
delete parameters;
parameters = NULL;
}Code: Select all
SFSObject::GetByte(string* key);
SFSObject::PutBoot(string* key,bool* val);
these points is need delete by self;What I mean is a function best to state those pointers need to manage, which is not required。
This is my understanding, do not know right, if the use of the wrong, it will cause memory leaks。
(String * key) as a parameter, and is very troublesome to use。
for example:
way1:
Code: Select all
SFSObject *obj = new SFSObject();
string sName = "name";
string sPwd = "password";
string sZone = "zone";
string sGame = "Game";
obj->PutUtfString(&sName,&userName);
obj->PutUtfString(&sPwd,&userName);
obj->PutUtfString(&sZone,&sGame);
//TODO: send cmd;
delete obj;Code: Select all
SFSObject *obj = new SFSObject();
string sName = new string("name");
string sPwd = new string("password");
string sZone = new string("zone");
string sGame = new string("Game");
obj->PutUtfString(sName,&userName);
obj->PutUtfString(sPwd,&userName);
obj->PutUtfString(sZone,&sGame);
//TODO: send cmd;
delete obj;
delete sName;
delete sPwd;
delete sZone;
delete sGame;but use other ClientAPI(like ObjectC)
Code: Select all
SFSObject *obj = [[SFSObject newInstance] autorelease];
[obj putUtfString:@"name" value:[NSString stringWithUTF8String:userName.c_str()]];
[obj putUtfString:@"password" value:[NSString stringWithUTF8String:userName.c_str()]];
[obj putUtfString:@"zone" value:@"Game"];if Modify
Code: Select all
SFSObject::GetByte(const string& key);Code: Select all
SFSObject::GetByte(const char *pKey);Code: Select all
SFSObject *obj = new SFSObject();
obj->PutUtfString("name",&userName);
obj->PutUtfString("password",&userName);
obj->PutUtfString("zone","Game");
//TODO: send cmd;
delete obj;