Author Topic: Aligning on 64k boundary  (Read 206 times)

Doug Clark

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 19
  • Posts: 203
    • View Profile
Aligning on 64k boundary
« on: September 14, 2020, 05:34:10 pm »
The Control Program reference says in the Remarks for DosWrite()

"When writing message pipes the application is limited to 64K messages. As well, these messages cannot span 64k boundaries due to the current design of the thunk layer in read or write routines. If the message is not written in an aligned manner, the subsequent read will not be able to handle the messages properly."

Since this is talking about thunking I assume it is for the 32 bit version of OS/2 rather than a relic from the 286 version of OS/2.  And besides you need to be able to read/write to a pipe from WinOS2.

How do you allocate memory (a buffer for a message) so that it does not cross a 64k boundary? 

I am programming in C - specifically VisualAge.

I don't see anything specific in DosAllocMem().   The #pragma pack only addresses alignment to 1,2,4,8 or 16 byte  alignments.

Rich Walsh

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 13
  • Posts: 128
  • ONU! (OS/2 is NOT Unix!)
    • View Profile
Re: Aligning on 64k boundary
« Reply #1 on: September 14, 2020, 05:56:27 pm »
How do you allocate memory (a buffer for a message) so that it does not cross a 64k boundary? 
I don't see anything specific in DosAllocMem().

If you invoke DosAllocMem() and don't explicitly use the high-memory flag ("OBJ_ANY"), you will always get a buffer aligned on a 64k segment boundary. There is an "OBJ_TILE" flag but it is redundant since low-memory is already tiled.

Alignment issues are a bigger concern if you're using memory allocated from the heap because that could start anywhere. You might have to allocate up 128k in order to have a full 64k that starts at xxxx0000.

Doug Clark

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 19
  • Posts: 203
    • View Profile
Re: Aligning on 64k boundary
« Reply #2 on: September 15, 2020, 12:15:03 am »
Thanks Rich.