Reputation: 1414
Good afternoon, We are building a prototype of a deduplication program with C++ on Windows and Linux. Yesterday, we posted a question on Stack Overflow about how to avoid the STL string
deep copying when we store a std::string
version of a record to deduped in the std::string* StringArray
, STL makes a deep copy of the string
and malloc
s a new buffer of at least 160,000,000 bytes. We quickly run out of heap memory and get a std::bad_alloc
exception
The Stack Overflow experts who answered out question recommending using a better string class such as SGI's Ropes becuases Ropes is buit especially for handling very large strings. So we downloaded a version of SGI's ropes.c and rope.h. However, we could not compile ropes.c and ropes.h on Windows Visual Studio 2008. Also, we couldn't find any examples of how to use the SGI C++ Ropes interface.
So we downloaded a Better String Library by Paul Hsieh. we modified our STL source code to use the bstring
class implemnted in a Better String Libary. Here is an excerpt of our code:
std::vector< bstring > BStringVector;
bstring b = bfromcstr(curr.getPtr());
char* const resultptr = (curr.getPtr() + n);
resultptr[STRING_SIZE] = '\x0';
BStringVector.push_back(b);
curr.mPtr = (char*)bstr2cstr(BStringVector.back(),' ');
std::multiset<Range>::iterator miter = ranges_type.lower_bound(Range(n));
(*miter).mPtr = curr.mPtr;
free (b);
return (char*)(resultptr);
This new code generates fewer std::bad_alloc
exceptions than the STL string
class, But we know Ropes is the best class for handling very large strings. So we need to know how to use the SGI source on Windows Visual Studio 2008. There are a lot of SGI specific header files in the Ropes code. What are the corresponding Windows Visual Studio 2008 C++ header file?
Also, after reading the Ropes documentation we are still not 90% positive about how to convert the null-terminated contents of a C/C++ char*
pointer to a Ropes object. In addition, how do we push_back
a Ropes object onto a STL container such as vector
? Finally, how do we retrieve the Ropes object from the STL vector
container? Thank you.
Upvotes: 0
Views: 712
Reputation: 24351
Did you download only the two implementation files? I doubt that this would work as they most likely rely on other files that are part of the SGI STL implementation. That would explain why you can't build them...
The easiest way to get at the SGI rope implementation might be to use STLport, which is a port and further development of the SGI STL to multiple platforms. I haven't tried using it with VS2008 though, but I'm pretty sure it's supported.
However, you will need to use STLport as a complete STL replacement (which it is) instead of extracting one or two classes and attempt to use that with the STL implementation that ships with VS2008.
That is, unless you fancy rewriting the rope classes to work out of the box with the MS STL, but that doesn't sound like a good idea to me.
Upvotes: 1