Board index » delphi » Adressing more than 64K in one contigious piece.

Adressing more than 64K in one contigious piece.

The structure I want to achieve is something like this:

Program Much_Mem;

var
  f: file;
  m: array[0..$FFFF] of byte;
  l: word;

begin
  assign(f,'Somefile');
  reset(f,1);
  blockread(f, m, LengthOf(m), l);
  ...
  ...  
end.

but this is impossible because of the 64K data-segment limit.
I would like to access 64K and have some other variables available
too. Any solutions????

Ate Wijma

 

Re:Adressing more than 64K in one contigious piece.


Quote
In article <DM5o3G....@rug.nl>, A.J.Wi...@cpedu.rug.nl (Ate Wijma) writes:

> The structure I want to achieve is something like this:

> Program Much_Mem;

> var
>   f: file;
>   m: array[0..$FFFF] of byte;
>   l: word;

> begin
>   assign(f,'Somefile');
>   reset(f,1);
>   blockread(f, m, LengthOf(m), l);
>   ...
>   ...  
> end.

> but this is impossible because of the 64K data-segment limit.
> I would like to access 64K and have some other variables available
> too. Any solutions????

> Ate Wijma

--

Use pointers !!!

Here's a short example :

{****************}
type TByteArr = array [0..65527] of byte;
     PByteArr = ^TByteArr;
var  m : PByteArr
     f : file;
     l : word;
begin
  New(m);
  Assign(f,'myfile.dat');
  Reset(f,1);
  BlockRead(f,m,SizeOf(TByteArr),l);
  .....
end;

Note that you can't declare an array of exactly 65536 bytes, you'll get a
structire too large error. You can only have an array 65535 bytes long.

If you use pointers however, you can't be sure that TP will be able to allocate
more than 65528 bytes. That's because of segment alignment. The heap manager
allocates variables on the Heap with an offset of either 0 or 8. If it's 0 you
can have 64K variable, if it's 8 you can have only 65528 bytes.
The problem is that you don't know if the offset will be 0 or 8 (unless it's
the first pointer to be allocated). A solution is to write a custom Heap
manager that alignes variables to segments if they are larger than 65528 bytes.

Vladan Bato
i3100...@univ.trieste.it

Re:Adressing more than 64K in one contigious piece.


On 06 Feb 96 (15:52), A.J.Wi...@cpedu.rug.nl wrote:

Quote

> The structure I want to achieve is something like this:

> Program Much_Mem;

> var
>   f: file;
>   m: array[0..$FFFF] of byte;
>   l: word;

> begin
>   assign(f,'Somefile');
>   reset(f,1);
>   blockread(f, m, LengthOf(m), l);
>   ...
>   ...
> end.

> but this is impossible because of the 64K data-segment limit.
> I would like to access 64K and have some other variables available
> too. Any solutions????

Yes, just use some large memory blocks and store a pointer to them
in your data segment.

type
  PBlock = ^TBlock;
  TBlock = array[0..BlockSize - 1] of byte;

var
  Block: PBlock;

begin
  Block := New(PBlock);

  [...]

  Dispose(Block);
end;

Quote

> Ate Wijma

Stephan

-------------------------------------------------------------------------
 Stephan A. Maciej   step...@maciej.muc.de   http://www.muc.de/~stephanm
       <<< Bug is a registered trademark of Microsoft Corp. >>>
-------------------------------------------------------------------------

Re:Adressing more than 64K in one contigious piece.


Hello Stephan!

 SAM> From: step...@maciej.muc.de (Stephan A. Maciej)

 SAM> On 06 Feb 96 (15:52), A.J.Wi...@cpedu.rug.nl wrote:

 SAM> type
 SAM>   PBlock = ^TBlock;
 SAM>   TBlock = array[0..BlockSize - 1] of byte;

 SAM> var
 SAM>   m: PBlock;

 SAM> begin
 SAM>   m := New(PBlock);

 SAM>   [...]
 >> assign(f,'Somefile');
 >> reset(f,1);
 >> blockread(f, m^, SIZEOF(Tblock), l);

 SAM>   Dispose(Block);
 SAM> end;

I just quote{*word*30}ed in order to show the way to pout data into an area
references by a pointer, and not put 64Kb data into the area starting where the
pointeris, which 10:1 is not where you'd want to put 64kb.

If you know very little of pointer and hot to put something in the area for
one., nor the need to NEW or GETMEM that area first, then you'll find you first
attempt at using poiunters will go wrong - very wrong.

Regards
Mikkel Breiler Cosysop Renoz BBS, Vinyl/Intuition

Other Threads