Solved

In memory file

Posted on 2004-08-19
7
333 Views
Last Modified: 2010-04-05
Is there a way to create a "virtual" file that is in memory only. What I would like to do is somehow create a section of memory that can be read and written to like a standard file using the file functions Sysutils.FileRead,Sysutils.FileWrite,Sysutils.Fileseek, etc...

The reason I wan to do this is I already have a class written that uses a temporary file as a buffer, but I would like to utilize RAM first if it is available.
0
Comment
Question by:rbohac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 13

Assisted Solution

by:BlackTigerX
BlackTigerX earned 40 total points
ID: 11843166
not exactly those functions, but you can use MMF (Memory mapped files)

there are many documents about that...

http://www.delphipages.com/news/detaildocs.cfm?ID=100
0
 
LVL 3

Assisted Solution

by:BJThomsen
BJThomsen earned 40 total points
ID: 11846152
If you rewrote your class to use a TStream, you could choose TFileStream or TMemoryStream interchangably.
0
 
LVL 6

Accepted Solution

by:
gwalkeriq earned 80 total points
ID: 11846788

Memory mapped files have some limitation that make them awkward to work with, specifically, dynamically changing the size of the file once is is created.

If you have a lot of complex code using FileRead, FileWrite, etc. it is not too bad to create your own class based on tMemoryStream, and then create FileRead, FileWrite, etc. methods for the stream class.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Assisted Solution

by:Molando
Molando earned 40 total points
ID: 11846855
if you are going to share your data between programs then you need to go down the memory mapped file route (or pass the data with wm_copydata. wm_copy data if it is just a small bit of data. Memory mapped files are likefiles on your harddrive, but just in memory. Only big problem with them is you can not resize them .
if you do not need to share the data between programs, then the TStream class as stated by BJThomsen is the best way to go.
0
 
LVL 34

Assisted Solution

by:Slick812
Slick812 earned 50 total points
ID: 11848160
????
You can use RAM if you want,  as a pointer (from a  GetMem( ) ), , , and Then the TFileStream has a Write and WriteBuffer method that you can get the pointer Data to the file, you will need to dereference the pointer^, but you will need to know the size of the memoery block you want to write. .
( I think you could use the  FileWrite  and just dereference the pointer^)
 or I would use a TMemoryStream, ,
I beleive the TMemoryStream has a SaveToFile method, which writes the entire memory block to a file
0
 
LVL 6

Assisted Solution

by:gwalkeriq
gwalkeriq earned 80 total points
ID: 11852249
I should also remind you that if you use a memorystream, and it is too big to fit into RAM, the operating system will write it to disk as backup store -- This is virtual memory, it generally works well. Thus, you should write to memory for temporary buffers, write to disk for persistance.
0
 
LVL 6

Author Comment

by:rbohac
ID: 12006416
All of these answers were very insightful. Thank you!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question