"jack" <id***@yahoo.com> wrote in message
news:40**********************@news.rcn.com...
Hi there,
I have an NxK matrix of strings (C++).
I'd like to write it to a binary file
and later read it back to C++ (since the
dimension N is huge, I'd like to save
some time reading it every time).
What's the best way (neat and fast) to do this without converting to C
character
array or create extra storage for the size
of each string?
Thank you for your help.
I don't see what advantage you think a C character array will give you. You
still have the same problem that you are trying to write parts of a large
file where each part is a different size. One way around this is to assume
some fixed maximum size, it certainly makes things simpler.
Another issue that greatly affects how you should do this is whether the
parts of the files might change size, so you read some strings of one size
but then you change the sizes and want to write different size strings to
the same place in the file.
Undoubtedly the fastest and neatest way to do this is to find some third
party library that has already solved the problem for you. This sort of
thing has been done countless times before. You could for instance look at a
B-Tree implementation. A B-Tree is a kind of indexed data structure
specialised to be stored in a file. In your case the index would presumably
be the first index of your matrix.
It's hard to give more specific advice because your problem is only vaguely
specified. Why not post back explaining *what* you are trying to achieve,
not *how* you are trying to achieve it.
john