• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to encode STL vector
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to encode STL vector


  • Subject: Re: How to encode STL vector
  • From: "Clark S. Cox III" <email@hidden>
  • Date: Thu, 7 Nov 2002 08:15:44 -0500

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Wednesday, Nov 6, 2002, at 22:38 US/Eastern, James Montgomerie wrote:

On Wednesday, November 6, 2002, at 02:42 PM, Arthur Clemens wrote:

Thanks, this works. Only the archivers really don't like a vector with no elements, so as a workaround I first tried to use conditionals: if (size > 0)
but that gives another error when reading back in: "byte expected".
So I now always keep one element in the vector array. It's a bit annoying.
...

You can encode it just like you would a plain C array:

//Encode
const unsigned size = myVector.size();
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &size];
[aCoder encodeArrayOfObjCType: @encode(unsigned) count: size at: &myVector.front()];


//Decode
unsigned size;
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &size];
myVector.resize(size);
[aCoder decodeArrayOfObjCType: @encode(unsigned) count: size at: &myVector.front()];

Note, however, that though in all the implementations I know of, &myVector.front() does return an pointer to the Vector's internal array, I don't believe it's guaranteed to by the standard. I think that a Vector can use any O(1) storage, and if it did (or changed to in the future) use something other than a plain array, your code would break (because, for example, the second item is not guaranteed to be adjacent in memory to the first).

Of all of the requirements imposed on std::vector (and it's iterators) by the standard, the only logical implementation is to have a contiguous block of memory. In addition, future versions of the standard are likely to make this explicit instead of implicit.


- -- http://homepage.mac.com/clarkcox3/
email@hidden
Clark S. Cox, III
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (Darwin)

iEYEARECAAYFAj3KZ4oACgkQd6STocYT1xUIJwCgkzqFe0ZT/1z+Q76GyweNsVAh
ZdMAn3NGI8kyUER4qjRHK/cVe/EgcQnK
=55SQ
-----END PGP SIGNATURE-----
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: How to encode STL vector (From: James Montgomerie <email@hidden>)

  • Prev by Date: RE: Window Placement
  • Next by Date: Copying files to an iDisk
  • Previous by thread: Re: How to encode STL vector
  • Next by thread: Re: How to encode STL vector
  • Index(es):
    • Date
    • Thread