Solved

In memory file

Posted on 2004-08-19
7
324 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 93
Delphi inherited method 6 68
Convert MS Word document to a PDF file 9 80
DBCtrlGrid, Delphi, Scroll 8 13
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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