Allocating memory under protected mode (BP7) 
Author Message
 Allocating memory under protected mode (BP7)

Hi, I'm looking for ways to allocate more than 64k memory in one piece on
BP7 protected mode, either as one-piece (flat memory model) or
pierced-together. I would prefer flat memory model for storing data
sequentially, but any Pascal unit which has extensive DPMI features would be
nice. I'd be glad if you folks know anything about this issue... Thanks :)


Wed, 18 Jun 1902 08:00:00 GMT  
 Allocating memory under protected mode (BP7)

Quote:

> Hi, I'm looking for ways to allocate more than 64k memory in one piece on
> BP7 protected mode, either as one-piece (flat memory model) or
> pierced-together. I would prefer flat memory model for storing data
> sequentially, but any pascal unit which has extensive DPMI features would be
> nice. I'd be glad if you folks know anything about this issue... Thanks :)

With BP 7 I'm afraid you cannot. It is not a BP 7 issue, but a 16-bit
limitation. You have no addressing mode available to use it.

Another suggestion:
Use either a true 32 bit compiler like FPC, GNU or P32 or TMT or ...
found on the TP-links, chapter "compilers" or use Delphi. No, you need
not be surprised: there is the PasW32 package of units tu make D3
compile BP 7 programs on a 32 bit platform.
http://www.geocities.com/SiliconValley/2926/tpf.html
--
Franz Glaser, Glasau 3, A-4191 Vorderweissenbach Austria ++43-7219-7035
Muehlviertler Elektronik Glaser. Industrial control and instrumentation
-----------------------------------------------------------------------

http://www.geocities.com/~franzglaser  http://members.xoom.com/f_glaser



Wed, 18 Jun 1902 08:00:00 GMT  
 Allocating memory under protected mode (BP7)

Quote:


> > Hi, I'm looking for ways to allocate more than 64k memory in one piece on
> > BP7 protected mode, either as one-piece (flat memory model) or
> > pierced-together. I would prefer flat memory model for storing data
> > sequentially, but any pascal unit which has extensive DPMI features would be
> > nice. I'd be glad if you folks know anything about this issue... Thanks :)

> With BP 7 I'm afraid you cannot. It is not a BP 7 issue, but a 16-bit
> limitation. You have no addressing mode available to use it.

On the contrary, *yes* you can.  DPMI allows you to allocate huge blocks,
using GlobalAlloc() or GlobalAllocPtr() in the WinAPI unit.  The chapter on
protected mode programming in the Language Guide has source which shows
exactly how to allocate and address the allocated memory by using
SelectorInc.  This satisfies the "pieced together" method requested.

Quote:
> [...]
> --
> Franz Glaser, Glasau 3, A-4191 Vorderweissenbach Austria ++43-7219-7035
> Muehlviertler Elektronik Glaser. Industrial control and instrumentation
> -----------------------------------------------------------------------

> http://www.geocities.com/~franzglaser  http://members.xoom.com/f_glaser

--
Scott Earnest            | SPAM protection in effect. Remove  |





Wed, 18 Jun 1902 08:00:00 GMT  
 Allocating memory under protected mode (BP7)

Quote:

>On the contrary, *yes* you can.  DPMI allows you to allocate huge blocks,
>using GlobalAlloc() or GlobalAllocPtr() in the WinAPI unit.  The chapter on
>protected mode programming in the Language Guide has source which shows
>exactly how to allocate and address the allocated memory by using
>SelectorInc.  This satisfies the "pieced together" method requested.

Thanks. Currently I have a unit which allocated memory in chunks of 64k each
using GlobalAlloc, and then uses GlobalLock to obtain pointer to the memory,
and then uses combination of seg(), ofs() and MEM[seg:oft] array to access
the data. Is it possible, for example to allocate 128k block, and then
obtain pointer to the 64k portion at the end? I'm asking this because I do
not fully understand how the pointer and seg()/ofs() is related under
protected mode. Thanks :)

<.sig is being worked on>



Wed, 18 Jun 1902 08:00:00 GMT  
 Allocating memory under protected mode (BP7)

Quote:


> >On the contrary, *yes* you can.  DPMI allows you to allocate huge blocks,
> >using GlobalAlloc() or GlobalAllocPtr() in the WinAPI unit.  The chapter on
> >protected mode programming in the Language Guide has source which shows
> >exactly how to allocate and address the allocated memory by using
> >SelectorInc.  This satisfies the "pieced together" method requested.

> Thanks. Currently I have a unit which allocated memory in chunks of 64k each
> using GlobalAlloc, and then uses GlobalLock to obtain pointer to the memory,
> and then uses combination of seg(), ofs() and MEM[seg:oft] array to access
> the data. Is it possible, for example to allocate 128k block, and then
> obtain pointer to the 64k portion at the end? I'm asking this because I do
> not fully understand how the pointer and seg()/ofs() is related under
> protected mode. Thanks :)

Protected mode doesn't use segment/offset addressing.  While offsets are more
or less based on a similar principal, segment registers must contain selector
values, where a selector is a pointer to a table stored in memory, managed by
the protected mode system (generally, you'll probably never touch that table
directly).  You can't really rely on the segment/offset thinking any longer.

Suppose you perform an allocation such as:

  p := GlobalAllocPtr (gmem_Fixed,131072); {allocate 128KB}

Assuming p<>nil, you can use the function shown in the Language Guide to get a
second pointer to an absolute offset in that block:

function GetPtr (p : pointer; offset : longint) : pointer;

type
  long = record
    lo, hi : word;
  end;

begin
  GetPtr := ptr(long(p).hi+long(offset).hi*SelectorInc,
                long(p).lo+long(offset).lo);
end;

You can call this function whenever you want to get a valid address to some
area of the entire allocated block.

Does this help any further?

Quote:
> <.sig is being worked on>

--
Scott Earnest            | SPAM protection in effect. Remove  |





Wed, 18 Jun 1902 08:00:00 GMT  
 Allocating memory under protected mode (BP7)
Quote:

>Protected mode doesn't use segment/offset addressing.  While offsets are
more
>or less based on a similar principal, segment registers must contain
selector
>values, where a selector is a pointer to a table stored in memory, managed
by
>the protected mode system (generally, you'll probably never touch that
table
>directly).  You can't really rely on the segment/offset thinking any

longer.

<very helpful code deleted>

Quote:

>Does this help any further?

Yeah, you answered my question perfectly :) Now I can play around with
protected mode better :)

Quote:

>--
>Scott Earnest            | SPAM protection in effect. Remove  |




--
.----------- _/ _/
_/ ------------------------------------------------------.
|           _______ /
|
|         _/      _/
|
|           ___ /    __ __ /  Minoru Toda
|

|
|        _____/    /  /  /
|
|                 /  /  /  <  .sig is being worked on >
|
|      __ __ /   __ __ /
|
|     /  /  /   /  /  /
|
|    __ __ /   /  /  /
|
|   /  /  /   /  /  /  Ex-Registered BeOS Developer, internet wierdo
|
| _______/
 _______/ -------------------------------------------------------'


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Q:Allocating memory in protected mode.

2. Protected mode & memory access (BP7)

3. Unexpected heap overflow in protected mode program compiled by BP7

4. BP7 + Protected mode apps + Windows 95/98 = slowdown

5. BP7: DLL in DOS protected mode program

6. BP7 protected mode chain to another program

7. BP7 Protected Mode Problems

8. Protected Mode and DMA with BP7

9. PLEEEEEASE Help - Pentium II and protected mode BP7

10. Windows NT4 + protected mode BP7 = problems ?

11. BP7-Protected Mode and P6 200Mhz machines

12. BP7 Protected mode crashes

 

 
Powered by phpBB® Forum Software