By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,315 Members | 1,736 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,315 IT Pros & Developers. It's quick & easy.

reading from a file without actually writing into its hard disk copy

P: n/a
Hi,

I have an array of data (which I am getting from a socket connection).
I am working on a program which acts on this data but the program is
written to work on data from a file (not from an array). I cannot
change anything in the program but can add some features by which I
can convert this array of data into a file. The easiest thing would be
to write the data into a file (in hard disk) and use it. But I will be
working on thousands of such data, so this would be time consuming.

One more constraint is that, the data has to be written into a file in
binary format and read in ascii format (otherwise the data is not read
properly). Is there anyway I can achieve this (writing in binary
format and reading in ascii format) without actually writing the array
into harddisk (by just using RAM).

Thanks
Jeevan.
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Jeevan" <kj***********@yahoo.com> wrote in message
The easiest thing would be to write the data into a file (in hard disk)
and use it. But I will be working on thousands of such data, so this
would be time consuming.
tmpfile() is your friend. This is almost always implemented as a RAM file.
One more constraint is that, the data has to be written into a file in
binary format and read in ascii format (otherwise the data is not read
properly). Is there anyway I can achieve this (writing in binary
format and reading in ascii format) without actually writing the array
into harddisk (by just using RAM).

Unfortunately now you're in trouble, since you can't open a temporary file
as binary for writing and text for reading. The real solution is to change
your program design so that this isn't necessary.
Nov 13 '05 #2

P: n/a
Well, if you're in Unix/Linux, maybe you can use function "mmap".
The system call mmap() establishes a mapping between your process's
address space and a file.
You could map your file into RAM, then place your array on that memory
address.
But, maybe your data should be formated as ascii .....

Scott
"Jeevan" <kj***********@yahoo.com> wrote in message
news:a6*************************@posting.google.co m...
Hi,

I have an array of data (which I am getting from a socket connection).
I am working on a program which acts on this data but the program is
written to work on data from a file (not from an array). I cannot
change anything in the program but can add some features by which I
can convert this array of data into a file. The easiest thing would be
to write the data into a file (in hard disk) and use it. But I will be
working on thousands of such data, so this would be time consuming.

One more constraint is that, the data has to be written into a file in
binary format and read in ascii format (otherwise the data is not read
properly). Is there anyway I can achieve this (writing in binary
format and reading in ascii format) without actually writing the array
into harddisk (by just using RAM).

Thanks
Jeevan.

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.