473,385 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Attaching basic_string to preallocated buffer

I'd like to have data file with many strings and load them at once
using MapViewOfFile[Ex] and unload with UnmapViewOfFile. So I wouldn't
have to allocate memory for each string on heap.

How can I use basic_string<> attaching them to pointer to string
within mapped space so it wouldn't copy that string to internal
buffer?

--
Alvin777
Jul 22 '05 #1
2 2320

"Alvin777" <al******@mail.ru> wrote in message
news:1c**************************@posting.google.c om...
I'd like to have data file with many strings and load them at once
using MapViewOfFile[Ex] and unload with UnmapViewOfFile. So I wouldn't
have to allocate memory for each string on heap.

How can I use basic_string<> attaching them to pointer to string
within mapped space so it wouldn't copy that string to internal
buffer?


You cannot. Obviously there would be difficulties if, for instance,
std::string wanted to reallocate its buffer. It would be awkward to keep
track of whether it had a reallocated buffer, or one that was supplied by
the user.

I suggest you write your own string class that does what you want
(presumably one that never reallocates its buffer).

class StaticString
{
public:
StaticString(const char*);
...
private:
const char* buffer;
};

john
Jul 22 '05 #2
On 21 Feb 2004 00:51:58 -0800, al******@mail.ru (Alvin777) wrote:
I'd like to have data file with many strings and load them at once
using MapViewOfFile[Ex] and unload with UnmapViewOfFile. So I wouldn't
have to allocate memory for each string on heap.

How can I use basic_string<> attaching them to pointer to string
within mapped space so it wouldn't copy that string to internal
buffer?


You might find it easier to use std::iostream etc.

I don't think you can do this with basic_string. But I would be gladly
poven wrong <g>.
--
Bob Hairgrove
No**********@Home.com
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alex Perlov | last post by:
Let's say I have a string s; and I know exactly what allocator string s is using. Then I have separately allocated buffer char *buf = allocator<char>::allocate(buflen); which is initialized...
14
by: Dylan Nicholson | last post by:
Been playing around with this all day, and haven't found a solution I like yet. Assuming some initial function: void foo(std::string& src) { src += "some fixed string"; src += bar(); src...
7
by: Heinz Ozwirk | last post by:
Does the standard require that 1. the type of basic_string::npos is an unsigned type? 2. the value of basic_string::npos is the largest possible value of that type? And - only if both are...
1
by: ScottyO | last post by:
Hello, I have some legacy C++ code that was re-written as a managed class. I made a C++ class library with it and I want to use it in my C# program. I created a reference to it and it...
2
by: Jonathan Mcdougall | last post by:
Visual studio 2005 reports main.cpp(8) : warning C4996: 'std::basic_string<_Elem,_Traits,_Ax>::copy' was declared deprecated with this program: # include <string> int main()
1
by: sharmadeep1980 | last post by:
Hi All, I am facing a very unique problem while compling my project in "Release" build. The project is building in DEBUG mode but giving linking error on Release build. Here is the error:...
5
by: wolverine | last post by:
Hi I want to know how to use basic_string with unsigned short (I have mentioned below why i have to do this). Could any tell me some good references in this topic. I am new to creating a new...
0
by: wolverine | last post by:
Hi I want to know how to use basic_string with unsigned short (I have mentioned below why i have to do this). Could any tell me some good references in this topic. I am new to creating a new...
3
by: jason.cipriani | last post by:
I'm in a rather strange situation. I have a class that does some stuff and uses a buffer to hold some data in; the details aren't important but the buffer is an std::vector: class Something {...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.