Restored from previous forum. Originally posted by PB.
Sometimes I need to load a massive file (say 800 MB) into memory so I
can alter some bytes, then write it back to disk over itself. However,
let's say I have only 64 MB of RAM on my system. What would happen?
Would PureBasic crash? Would it use the paging file? I don't want to
wreck anyone's system by doing this when I release my app, you see...
You may ask why don't I directly modify the file on disk? Well, okay,
but what's the most efficient way to do this? I can't open the file
and write it to another -- what if there is only 20 MB free on the
drive? Besides, I must overwrite the existing file, not create another.
Any advice appreciated on the best way to accomplish this.
PB - Registered PureBasic Coder
Loading massive files into memory
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
If you're not altering the size of the file you can just use 'FileSeek(Pos)' and then alter the bytes that need changing with WriteByte() or whatever and then close the file. If you do alter the size it's a completely different story, you would have to read ahead from the position your altering and write back everything in front of that.
If you're not altering the size of the file you can just use 'FileSeek(Pos)' and then alter the bytes that need changing with WriteByte() or whatever and then close the file. If you do alter the size it's a completely different story, you would have to read ahead from the position your altering and write back everything in front of that.
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Berikco.

like me at viewtopic.php?t=2137">http://forums.pur ... nny.zeb.be
Sometimes the solution is so small you can`t see itOriginally posted by PB
Thanks Pupil -- that was so obvious (WriteByte) that I'm ashamed to admit
that I didn't even think of it.![]()

like me at viewtopic.php?t=2137">http://forums.pur ... nny.zeb.be
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> Sometimes the solution is so small you can`t see it
> like me at viewtopic.php?t=2137
Hehehe, yeah.
PB - Registered PureBasic Coder
> Sometimes the solution is so small you can`t see it

> like me at viewtopic.php?t=2137
Hehehe, yeah.
PB - Registered PureBasic Coder
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Danilo.
The question is already answered,
but i still want to say something:
PB, look at the Win32 API for FileMapping
functions.
With this System you map a part (lets say 1MB)
of the 800MB file into memory, work with it
and write this part back to disk later.
There are Editors out there (UltraEdit etc.)
that can edit 2GB files without a problem.
They dont load all the 2GB into memory,
but map only parts into memory.
Take a look at the Help in the free MS Platform SDK..
cya,
...Danilo
(registered PureBasic user)
The question is already answered,
but i still want to say something:

PB, look at the Win32 API for FileMapping
functions.
With this System you map a part (lets say 1MB)
of the 800MB file into memory, work with it
and write this part back to disk later.
There are Editors out there (UltraEdit etc.)
that can edit 2GB files without a problem.
They dont load all the 2GB into memory,
but map only parts into memory.
Take a look at the Help in the free MS Platform SDK..
cya,
...Danilo
(registered PureBasic user)
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm