Re: Variants



Lorin wrote:
So if I limit myself to Strings, User Defined Types and simple
types in a Variant is there a problem using the RTLMoveMemory?

For UDTs, arrays, objects etc (anything other than simple types), a
Variant always contains a pointer. Copying pointers blindly is a
recipe for crashes. VB doesn't expect that, so it doesn't accommodate
it.

Simple types, no problem. But strings in Variants are pointers, and I
can't see a scenario where it would be wise to use multiple copies of
a string pointer. By itself it's not an issue, but as soon as the
string goes out of scope or is otherwise destroyed via one pointer,
the other pointer becomes a time bomb.

If you're completely aware of the issues and vigilant about not
keeping dead pointers around or letting VB destroy them, maybe. But I
question how useful this would be, given the restrictions.

I have tried some memory operation on an array of variants holding
strings and an array of variants holding a user defined types and
it seems to work OK or am I just lucky and why?

You're just lucky -- so far. I can't say why. (-:

--
Jim

.



Relevant Pages

  • Re: What is wrong with this: *p++=*s++
    ... arrays are not pointers. ... > because you're treating 'p' as if it where an char pointer by trying ... > And the problem of the Matt has been already explained to him, strings ...
    (comp.lang.c)
  • Re: Array of type Variable length string
    ... You're setting up 16 million strings, ... > dim xas variant, ... > and later on you redimension them to 2D arrays, as the size of the array ... > takes to unload the array from memory. ...
    (microsoft.public.vb.controls)
  • Re: Whats wrong with strcpy/strcat in this "C for Tcl" experiment?
    ... EL> I conclude from this that whenever declaring a pointer, ... EL> allocate memory before writing to it. ... plain C does not have 'strings' in the same sense as Tcl (and ... In C pointers and arrays are often interchangeable -- esp. ...
    (comp.lang.tcl)
  • Re: How to convert from managed to unmanaged (and viceversa) byte arrays and strings???
    ... > converting from the managed to the unmanaged world (and viceversa strings) ... > and byte arrays is something I do often and I'd like to identify the most ... > garbage collector trying to reclaim memory that may not be freed (read ... if you have a managed string s and you need to pass a pointer to ...
    (microsoft.public.dotnet.framework.interop)
  • Re: How to convert from managed to unmanaged (and viceversa) byte arrays and strings???
    ... > converting from the managed to the unmanaged world (and viceversa strings) ... > and byte arrays is something I do often and I'd like to identify the most ... > garbage collector trying to reclaim memory that may not be freed (read ... if you have a managed string s and you need to pass a pointer to ...
    (microsoft.public.dotnet.languages.vc)

Loading