Jump to content
Registration disabled at the moment Read more... ×
sfrazor

Compiler Linker Question

Recommended Posts

When building a DLL, I have a series of arrays that I want compiled together in the binary.  Perhaps like a packed record.  I'm not sure I'm asking this question correctly....

 

For example

item1: array [0..64] of ansichar

item2: array [0..64] of ansichar

item3: array [0..64] of ansichar

 

I want the compiler/linker to keep them together in the binary so I can open the DLL and do a replace on 192 contiguous bytes.  The compiler seems to move these around and not contiguous.

 

Is there a way, or a better way to achieve this without using a packed record?

 

I've searched the compiler and linker flags but I don't see anything that looks obvious.  The Align flag doesn't seem to be what I'm looking for.

 

 

 

Share this post


Link to post

Yes, a packed record is the way to go to control memory layout as much as possible.

Share this post


Link to post

Thank you.  I was afraid that was the answer.  I have some refactoring to do of some rather ugly code. 

Share this post


Link to post

If you want the arrays contiguous, then why not just use a single array?

const
  itemSize = 65;
  numItems = 3;

var
  items: array[0..(itemSize*numItems)-1] of AnsiChar;

function item1: PAnsiChar;
begin
  Result := @items[0];
end;

function item2: PAnsiChar;
begin
  Result := @items[itemSize*1];
end;

function item3: PAnsiChar;
begin
  Result := @items[itemSize*2];
end;

Or:

const
  itemSize = 65;
  numItems = 3;

type
  itemType = array[0..itemSize-1] of AnsiChar;

var
  items: array[0..numItems-1] of itemType;

function item1: PAnsiChar;
begin
  Result := @items[0][0];
end;

function item2: PAnsiChar;
begin
  Result := @items[1][0];
end;

function item3: PAnsiChar;
begin
  Result := @items[2][0];
end;

 

Edited by Remy Lebeau
  • Like 1

Share this post


Link to post

Sorry for the late reply.  That was a wow moment!  I honestly didn't even think of that.  That's a MUCH easier refactor than I was getting ready to do.  Thanks Remy.

I'll give it a try.  I'll have to figure out how to add a search marker so I can scan the binary for the beginning of the array.  

Edited by sfrazor

Share this post


Link to post

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×