alignment

General FreeBASIC programming questions.
Zamaster
Posts: 1025
Joined: Jun 20, 2005 21:40
Contact:

alignment

Postby Zamaster » Oct 16, 2014 5:16

When defining variables in freebasic, is it possible to force alignment like in c with "__attribute__ (alignment(16)) ".
dkl
Site Admin
Posts: 3212
Joined: Jul 28, 2005 14:45
Location: Germany

Re: alignment

Postby dkl » Oct 16, 2014 10:00

Zamaster
Posts: 1025
Joined: Jun 20, 2005 21:40
Contact:

Re: alignment

Postby Zamaster » Oct 17, 2014 20:52

okay :(. Anyone know a hack?
fxm
Posts: 9816
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: alignment

Postby fxm » Oct 20, 2014 11:19

What is your alignment need:
- For a variable?
- For an array?
- For a memory block?
...
Zamaster
Posts: 1025
Joined: Jun 20, 2005 21:40
Contact:

Re: alignment

Postby Zamaster » Oct 23, 2014 6:19

just a procedure scope variable
fxm
Posts: 9816
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: alignment

Postby fxm » Oct 23, 2014 7:22

Code: Select all

'' Hacking example for a local variable of LONG type (4 bytes), aligned to 16 bytes

Const As Integer align = 16           '' alignment value (in bytes)
Const As Integer size = Sizeof(Long)  '' variable size (in bytes)


Dim As Byte memBlockLong(0 To size-1 + align-1)
Dim As Long Ptr pLong = Cast(Any Ptr, @memBlockLong(0) + align-1 - Cast(Ulong, @memBlockLong(0) + align-1) Mod align)

'' The LONG variable '*pLong' is aligned to 16 bytes
*pLong = 123456789
Print "@&h" & Hex(pLong) & ": " & *pLong

Sleep

Code: Select all

@&h12FEE0: 123456789
Zamaster
Posts: 1025
Joined: Jun 20, 2005 21:40
Contact:

Re: alignment

Postby Zamaster » Oct 27, 2014 3:32

I ended up doing something just like this, thanks for the post!

Return to “General”

Who is online

Users browsing this forum: No registered users and 8 guests