Solved

In memory file

Posted on 2004-08-19
7
323 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
automatically logging in via bde delphi 3 69
Delphi cmd execution 6 55
Delphi selector screen 2 69
How to debug For loops? 3 45
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now