473,395 Members | 1,495 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,395 software developers and data experts.

How to make stringstream that reads file content from a memory

Dear All,

I have some C++ code which is autogenerated and reads data from a file
(numeric values). This external data file "Weights.asc" is not big
(11kb).

The rest of the code is expecting a passed FILE* pointer in order to
read properly the numeric values and compute stuff. This is real-time
application and thus reading / writing files is strongly prohibited and
time expensive.

The data I have is of the correct type but it is in memory. Is there a
way I can create a FILE structure and point it to the data in memory,
or generally convert my in memory data to a FILE structure?

Here is a part of the code:

FILE *loadStream = fopen("Weights.asc","r");

// Get the file version number
weightFileVersion = getWeightFileVersion(loadStream);

// Load Normalization Coefficients
inputFile.loadWeights(seekComponent(loadStream, "File",
"inputFile"),weightFileVersion);

ComputedOutput.loadWeights(seekComponent loadStream, "DataStorage",
"ComputedOutput"),weightFileVersion);

// Load A Weights
inputAxon.loadWeights(seekComponent(loadStream, "Axon",
"inputAxon"),weightFileVersion);
hidden1Axon.loadWeights(seekComponent(loadStream, "TanhAxon",
"hidden1Axon"),weightFileVersion);
outputAxon.loadWeights(seekComponent(loadStream, "LinearAxon",
"outputAxon"),weightFileVersion);

// Load S Weights
hidden1Synapse.loadWeights(seekComponent loadStream, "FullSynapse",
"hidden1Synapse"),weightFileVersion);
outputSynapse.loadWeights(seekComponent loadStream, "FullSynapse",
"outputSynapse"),weightFileVersion);

fclose(loadStream);

My question is whether I can use STRINGSTREAM to make a string variable
with the complete data in the memory and then use the pointer to the
data to execute the rest of the code.

Thank you for your help.
Laco.

Oct 20 '06 #1
1 2154
Laco wrote:
Dear All,

I have some C++ code which is autogenerated and reads data from a file
(numeric values). This external data file "Weights.asc" is not big
(11kb).

The rest of the code is expecting a passed FILE* pointer in order to
read properly the numeric values and compute stuff. This is real-time
application and thus reading / writing files is strongly prohibited and
time expensive.

The data I have is of the correct type but it is in memory. Is there a
way I can create a FILE structure and point it to the data in memory,
or generally convert my in memory data to a FILE structure?

Here is a part of the code:

FILE *loadStream = fopen("Weights.asc","r");

// Get the file version number
weightFileVersion = getWeightFileVersion(loadStream);

// Load Normalization Coefficients
inputFile.loadWeights(seekComponent(loadStream, "File",
"inputFile"),weightFileVersion);

ComputedOutput.loadWeights(seekComponent loadStream, "DataStorage",
"ComputedOutput"),weightFileVersion);

// Load A Weights
inputAxon.loadWeights(seekComponent(loadStream, "Axon",
"inputAxon"),weightFileVersion);
hidden1Axon.loadWeights(seekComponent(loadStream, "TanhAxon",
"hidden1Axon"),weightFileVersion);
outputAxon.loadWeights(seekComponent(loadStream, "LinearAxon",
"outputAxon"),weightFileVersion);

// Load S Weights
hidden1Synapse.loadWeights(seekComponent loadStream, "FullSynapse",
"hidden1Synapse"),weightFileVersion);
outputSynapse.loadWeights(seekComponent loadStream, "FullSynapse",
"outputSynapse"),weightFileVersion);

fclose(loadStream);

My question is whether I can use STRINGSTREAM to make a string variable
with the complete data in the memory and then use the pointer to the
data to execute the rest of the code.
You won't be able to point a FILE* to memory unless you can find some
platform-dependent functions to help you (ask for more info in a forum
for your platform; cf.
http://www.parashift.com/c++-faq-lit....html#faq-5.9). Apart
from that, you'll have to rewrite your functions at least a little bit
to make use of a stream (if you do this, you could make it use an
ostream& so that you can use an ostringstream or an fstream or
whatever).

Cheers! --M

Oct 20 '06 #2

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

Similar topics

5
by: Ellarco | last post by:
Im sorry for asking a question that is surely in the archives somewhere, but I have been unable to locate it. Its about string memory management. I need to dynamically construct a C-style string...
2
by: Steffen Conrad | last post by:
Hi, I want to buffer a large amount of ASCII-output (some 100 MB). Therefore I'm asking myself, if when using a stringstream for this would cause a mentionable loss of performance against a...
5
by: Marcin Kalicinski | last post by:
Is there a vectorstream class that implements the functionality similar to std::stringstream but with std::vector, not std::string? cheers, Marcin
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
5
by: ma740988 | last post by:
Consider: #include <iostream> #include <sstream> #include <string> int main ( ) { { double pi = 3.141592653589793238; std::stringstream a;
9
by: Àî°× | last post by:
hi all: I want erase a stringstream' content for input new data to it. example: std::stringstream stm; stm<<"this is a string"; std::cout<<stm.str(); // here print:this is a string
2
by: akitoto | last post by:
Hi there, I am using the std::stringstream to create a byte array in memory. But it is not working properly. Can anyone help me? Code: #include <vector> #include <sstream> #include...
5
by: Gary Wessle | last post by:
Hi how can I clear a stringstream? ss.clear(); or ss.flush(); thanks
82
by: Bill David | last post by:
SUBJECT: How to make this program more efficient? In my program, a thread will check update from server periodically and generate a stl::map for other part of this program to read data from....
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.