Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   How to make stringstream that reads file content from a memory (http://www.velocityreviews.com/forums/t457751-how-to-make-stringstream-that-reads-file-content-from-a-memory.html)

Laco 10-20-2006 12:44 PM

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.


mlimber 10-20-2006 01:02 PM

Re: How to make stringstream that reads file content from a memory
 
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



All times are GMT. The time now is 06:05 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.