C++/VB - Does DataRow::Item copy the data inserted or just the pointer?

Asked By AndersG on 13-Jan-12 08:38 AM


Cholo Lennon replied to AndersG on 16-Jan-12 10:33 AM
What's the type of Stringvar? Is a MFC string, std::string or Dot Net
String?


If Stringvar is a dot net String you do not have to create another string
with gcnew, just assign it to r->default[1];


If Stringvar is a Dot Net String you do not have to worry about its
lifetime, it is managed by GC. Dot net strings are managed by reference,
so technically you are coping a pointer, and it is ok.


--
Cholo Lennon
Bs.As.
ARG
AndersG replied to Cholo Lennon on 18-Jan-12 07:53 AM
Sorry, Stringvar is a CString
Cholo Lennon replied to AndersG on 18-Jan-12 10:54 PM
Ok, so your code is perfectly valid:

r->default[1] = gcnew String(Stringvar);

Stringvar is copied into a dot net string which is referenced by
r->default[1]. r and default[1] are dot net references. The referenced
objects will be released later by GC when he decide it (technically when
no references to them exist)

Regards

--
Cholo Lennon
Bs.As.
ARG