Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SEEKING IN FILES BIGGER THAN 2 GIG

Posted on 2006-06-23
9
Medium Priority
?
329 Views
Last Modified: 2010-04-04
Hello All,

I have a routine that reads in a file and as it reads the file in it writes out an index file like

index is
tdelimit_struct = record
recnum:longint;
spos:int64;
ssize:int64;
skey:array[1..10] of char;
end;

(* spos = start position in file, ssize is no of characters to read in *)

Once the data is read in a third party dll sorts the data and then supplies me back just the record no's i need for the sorted
data.

This is why the index is written as the data coming in can be delimitted or fixed field.

To read the data back in I have a tfilestream method....

seekf=tfilestream.create(ifile,fmopenread);
repeat
.
(* get record from sort , read sort key from main index then*)
.
(* and to seek a record *)
seekf.seek(delimit_struct.spos,soFromBeginning);
seekf.read(buffer,delimit_struct.ssize);

-- PROBLEM HERE ---------
The problem is when the file is over 2 gig i get a range check error on the seek - despite the fact i have a int64?

The offset crashing it was 2152430441 (which  is over 2gig).

I can seek seekf is meant to read over 2gig files?

I had similar problems with getting the size of the original files but fond code to fix this but the read is killing it?

HELP please!

This is in delphi7.

Thanks

Phil


0
Comment
Question by:PHILFRED
  • 4
  • 2
9 Comments
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16969653
Try
seekf.Position := delimit_struct.spos;
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16969781
Or use SetFilePointer win32 api function
e.g.
SetFilePointer(seekf.Handle, delimit_struct.spos, nil, FILE_BEGIN);
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16970100
Sorry the above example will not work with file >2 gb. use the following instead.

var
  MyRec : packed record L, H : cardinal end absolute i;
begin
  // your code
  SetFilePointer(fs.Handle, MyRec.L, @MyRec.H, FILE_BEGIN);
end;
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:PHILFRED
ID: 16970198
Thanks Atul - but how do i get the values into MyRec?

var
  MyRec : packed record L, H : cardinal end absolute i;
begin
  // your code
  SetFilePointer(fs.Handle, MyRec.L, @MyRec.H, FILE_BEGIN);
end;
0
 
LVL 10

Accepted Solution

by:
atul_parmar earned 500 total points
ID: 16970326
Phil, Sorry abt that!

var
  i : int64
  MyRec : packed record L, H : cardinal end absolute i;
begin
  // your code
  i := delimit_struct.spos;
  SetFilePointer(fs.Handle, MyRec.L, @MyRec.H, FILE_BEGIN);
  // because we appended the absolute to the MyRec it will point to the same location where i variable resides so will be initialized when we assign delimit_struct.spos to i (i.e. i := delimit_struct.spos;)
end

I hope, that will do. I m moving now. Happy Week end. :)

Atul.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 16970388
You can also skip the absolute mapping by using LARGE_INTEGER casting, eg:

Regards,
Russell

function GetSizeEx(Handle: THandle): Int64;
begin

  LARGE_INTEGER(result).LowPart:=GetFileSize(Handle, @LARGE_INTEGER(result).HighPart);

end;

procedure SetSizeEx(Handle: THandle; Size: Int64);
begin

  SetFilePointer(Handle, LARGE_INTEGER(Size).LowPart, @LARGE_INTEGER(Size).HighPart, FILE_END);
  Win32Check(SetEndOfFile(Handle));

end;

function SeekEx(Handle: THandle; Offset: Int64; Origin: Word): Int64;
begin

  result:=Offset;
  LARGE_INTEGER(result).LowPart:=SetFilePointer(Handle, LARGE_INTEGER(result).LowPart, @LARGE_INTEGER(result).HighPart, Origin);
  if (LARGE_INTEGER(result).LowPart = $FFFFFFFF) then RaiseLastWin32Error;

end;
0
 

Author Comment

by:PHILFRED
ID: 16970562
Ok Thanks all i will implement some code over the weekend and see what works!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

971 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