473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Stripping specific bytes of a file without opening the entire file...

Greetings all,

I have a group of rather large files (by group i mean close to 2x10^7
files, each 12-15megs) now i need information which is stored in just
the last 512 bytes of each file. i was wondering if there is a way to
strip out this information without loading the entire file into memory.
Right now im doing it with fopen() and fread() and it takes several
hours to process all the files. obviously i know exactly where the
information is, just wondering if i can somehow just open up the
trailing 512-1024 bytes. or even physically strip this info off the
file on the disc before opening it? thanks for the help. ps. im
working on a linux box, running fedora cora 2, using gcc v3.3.3

Cheers,
Adam.

Jul 23 '05 #1
7 1618

ba*****@gmail.com wrote:
Greetings all,

I have a group of rather large files (by group i mean close to 2x10^7
files, each 12-15megs) now i need information which is stored in just the last 512 bytes of each file. i was wondering if there is a way to strip out this information without loading the entire file into memory. Right now im doing it with fopen() and fread() and it takes several
hours to process all the files. obviously i know exactly where the
information is, just wondering if i can somehow just open up the
trailing 512-1024 bytes. or even physically strip this info off the
file on the disc before opening it? thanks for the help. ps. im
working on a linux box, running fedora cora 2, using gcc v3.3.3

Cheers,
Adam.


Try 'istream::seekg'

Hope this helps,
-shez-

Jul 23 '05 #2

ba*****@gmail.com wrote:
Greetings all,

I have a group of rather large files (by group i mean close to 2x10^7
files, each 12-15megs) now i need information which is stored in just the last 512 bytes of each file. i was wondering if there is a way to strip out this information without loading the entire file into memory. Right now im doing it with fopen() and fread() and it takes several
hours to process all the files. obviously i know exactly where the
information is, just wondering if i can somehow just open up the
trailing 512-1024 bytes. or even physically strip this info off the
file on the disc before opening it? thanks for the help. ps. im
working on a linux box, running fedora cora 2, using gcc v3.3.3

Your best bet is fseek() which allows you to position the file pointer
at a specified offset in the file. I don't think that you can avoid
opening the file in any event.

Regards,

Jon Trauntvein

Jul 23 '05 #3
yeah im trying to not open the entire file into memory. im using
fseek() once its called from fopen() but it still loads the entire
file into memory, which is a nusance. any other ideas?

Cheers,
Adam.

Jul 23 '05 #4
ff**@hotmail.com wrote:
yeah im trying to not open the entire file into memory. im using
fseek() once its called from fopen() but it still loads the entire
file into memory, which is a nusance. any other ideas?

Cheers,
Adam.


Try using platform specific functions to prevent the loading
of the file into memory. Just remember about portability
problems.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Jul 23 '05 #5

ff**@hotmail.com wrote:
yeah im trying to not open the entire file into memory. im using
fseek() once its called from fopen() but it still loads the entire
file into memory, which is a nusance. any other ideas?

Cheers,
Adam.


Why will seek functions (either fseek() or istream::seekg()) load the
entire file into memory? What kind of filesystem are you using? I
would think that if the filesystem provides enough information about
the physical layout of files on disk (e.g., inodes in unix), it
shouldn't need to load the entire file into memory.

Am I wrong?

-shez-

Jul 23 '05 #6
which platform specific functions are you thinking of? im running
fedora core 2 (redhat linux) on an ext3 file system. portability is
not a concern of mine. i just need it to run on ext3 filesystems.

cheers,
adam.

Jul 23 '05 #7

ff**@hotmail.com wrote:
which platform specific functions are you thinking of? im running
fedora core 2 (redhat linux) on an ext3 file system. portability is
not a concern of mine. i just need it to run on ext3 filesystems.

cheers,
adam.


This may not help you, but I just did some tests...on my system
(winXP), using fstream to open and seekg() to move around does not
cause the file to load into memory. I tested by opening a 30MB file,
seeking around, then seeking to the begining and loading the whole
thing into memory, and seeing how long it took/how much disk usage was
required between each step. The only operation that took any
significant time was loading the file. I then tested where I just
loaded a small fraction of the file, and it took much less time than
loading the full file.

HTH

Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Jeff North | last post by:
Hi, I'm using a control called HTMLArea which allows a person to enter text and converts the format instructions to html tags. Most of my users know nothing about html so this is perfect for my...
2
by: Patrick | last post by:
Hello, after learning that I was taking a class in VB.NET, I have been drafted to solve all my companies VB/scripting problems - hey, I should know everything; I've already taken 6 classes ;) I...
23
by: Francesco Zavatarelli | last post by:
I downloaded a free c-compiler and I'm trying to access a file in a windows directory c:\program files\... but I get an error when I run the code. Probably my declaration char* NAME is wrong....
8
by: james | last post by:
I am trying to use Filestream to read a file ( .DAT) that contains values in HEX that I want to convert to text. I know the different offset addresses for each portion of the data I am trying to...
25
by: gamehack | last post by:
Hi all, I'm writing an application which will be opening binary files with definite sizes for integers(2 byte integers and 4 byte longs). Is there a portable way in being sure that each integer...
26
by: ValK | last post by:
Hi, Here is my problem. I need to check if scanner finished scanning the document. I'm using scanner interface that came with the scanner. I tried to open file and catch IO Exception for "The...
2
by: Craig | last post by:
I have the need to write a byte of information to a specific location in a text file. eg. the file looks something like this. FYYNN Line 1 Line 2 <eof>
12
by: Dixie | last post by:
Is there a way to shell to Microsoft Word from Access and load a specific template - using VBA? dixie
17
by: broughcut | last post by:
Is it possible to fetch a specific div from a source html document using XMLHttpRequest, rather than fetching the entire file? I was going to use Ajax on mouseover but keep the normal link...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.