Re: Vector<T> length in bytes



ivan.kataitsev@xxxxxxxxx wrote:

=) Mark, thank u for your help, but in context of my task i need to
know exactly the "length" in bytes, not memory allocation of byte[].
After some actions all data will be send to the some output stream anf

Andrea and Lew are both right. You basically have to do this yourself. Even in C, you have some questions about what exactly you are going to measure the size of. An array of pointers is likely to be much smaller than the buffers it points to, but that would be the size of the array. The buffers OTOH are probably what you want transmit, but if you used a general memory counting algorithm, you'd likely have the size of the array of pointers included.

It won't work as you imagine, in any language. An image of memory is not dumped on the wire and then read by the other end. At least, I think that would be incredibly hard to maintain.

You'll need to define the problem a bit better. Andrea's suggestion isn't bad, especially if you have a disk you can spool to, or you're sure that you can hold all your buffers in memory.

You might also try to send each object in the Vector separately. That might be easier than trying to mash them all together first. HTTP does this when sending pages. First the HTML is sent, then the images are loaded one at a time. It's not one huge bundle.

Better yet would be to use a protocol that does not require you to know the size before you send, but that may not be an option if you are trying to send a single GIF or something. However, I'll mention that I think using Java's serialization directly does do this--you don't need the total number of bytes before you start sending. It might be an option.

Anyway, good luck. Let us know if you work it out.
.



Relevant Pages

  • Re: Dusty Deck and C memory manager, Part 1
    ... CMEMC.C -- C memory management routines for use with FORTRAN. ... Return an index into ARRAY representing LENGTH words of available ... void *ptr, *malloc; ... Rather than introduce Cray pointers and use C routines to allocate memory for Fortran arrays, you could use straight F90, for example: ...
    (comp.lang.fortran)
  • Re: Simple C containers, std::vector analog
    ... You're right about not needing to care very much about the memory ... blocks, in not knowing the ultimate size of the growable array, because ... there is no realloc function, and besides realloc might be having ... whether it's used for the list of array block pointers only or a C++ ...
    (comp.lang.c)
  • Re: Differance between Array and Pointers
    ... Well, except that arrays tend to be much larger than pointers, and the ... An array is a contiguous region of memory containing N elements of M ... indexing vs. a loop). ...
    (comp.arch.embedded)
  • Re: far pointer
    ... has nothing to do with comparing pointers for equality. ... > array y is probably next to array x in memory. ... and doesn't require segmented memory. ...
    (comp.lang.c)
  • Re: far pointer
    ... The restriction that pointers must be calculated within the object, has nothing to do with comparing pointers for equality. ... array y is probably next to array x in memory. ... and doesn't require segmented memory. ...
    (comp.lang.c)

Loading