Pointer in Basic
#24
(07-19-2023, 10:27 AM)SagaraS Wrote:
(07-18-2023, 10:11 PM)SMcNeill Wrote: It's all about what's most efficient, in general cases, for the OS to read/write data.  (Note that things like #pragma pack and such alters such behavior.)  Generally speaking, the OS is going to write data in 4-bytes (sectors if you want) on a 32-bit App and in 8-byte sectors on a 64-bit App.

>> NOTICE I SAID APP AND NOT OS!!  64-bit OSes will still pack 32-bit programs into 4-byte sectors, rather than 8-byte sectors, so everything defaults for compatibility reasons.  <<
And why does QB64 reserve the same variables for me on a 32-bit OS in a 32-bit APP? So always 8 bytes for each variable.
Shouldn't that be at least 4 bytes?

I don't quite get it.

QB64 would then have to reserve something else. And the gaps are never really filled. I've already declared umpteen variables and restarted the program. On a 64-bit as well as on a 32-bit OS. With a 32-bit app as well as with a 64-bit app of the same program.
And again and again I can observe the same thing in the memory viewer.

Do you have some example code that better illustrates that the memory behaves differently?

Because I can't reproduce it no matter what I do instead.

My Visual Studio C++ app works like you say. But somehow QB64 doesn't intend to do what you're telling me.

Don't get me wrong, I know what you're saying and how the memory should work. But somehow QB64 doesn't want to keep that ^^
You're right, from what I can tell.  O_o!  

Older versions used to align on 4-byte boundaries with 32-bit apps.  When I tested our latest version, it aligns on 8-byte boundaries -- most of the time!

PRINT _OFFSET(a), _OFFSET(b), _OFFSET(c)

Run the above, as is, without bothering to declare any variable type (it'll default to SINGLE), and see the spacing -- it's 32-bytes!

It's just another reason to keep in mind that it's all up to the OS for where/how it places your data in memory.  I wouldn't trust that the space between is always going to be 8-bytes for anything. (Especially if mem usage starts to increase and the OS starts to reshuffle and pack program memory.)

WHY the 32-bit apps now appear to align on 8-byte memory spaces is a mystery to me.  It may be the g++ guys tweaked something moving up from v11 to v17 (or whatever the lastest version is now).  Personally, I'd just always rely on _OFFSET or MEM.OFFSET to let the program tell me where my data is in memory.  If I was truly concerned about always packing things without any spaces, then I'd just declare a _MEMNEW block and micromanage placement manually.
Reply


Messages In This Thread
Pointer in Basic - by Kernelpanic - 07-16-2023, 09:57 PM
RE: Pointer in Basic - by bplus - 07-16-2023, 10:17 PM
RE: Pointer in Basic - by mnrvovrfc - 07-17-2023, 12:05 AM
RE: Pointer in Basic - by SagaraS - 07-17-2023, 12:17 AM
RE: Pointer in Basic - by OldMoses - 07-17-2023, 12:40 AM
RE: Pointer in Basic - by bplus - 07-17-2023, 01:00 AM
RE: Pointer in Basic - by a740g - 07-17-2023, 02:53 AM
RE: Pointer in Basic - by SpriggsySpriggs - 07-17-2023, 11:55 AM
RE: Pointer in Basic - by Kernelpanic - 07-17-2023, 07:04 PM
RE: Pointer in Basic - by SagaraS - 07-17-2023, 09:39 PM
RE: Pointer in Basic - by mnrvovrfc - 07-17-2023, 10:52 PM
RE: Pointer in Basic - by Kernelpanic - 07-18-2023, 12:17 AM
RE: Pointer in Basic - by SagaraS - 07-18-2023, 02:42 AM
RE: Pointer in Basic - by bplus - 07-18-2023, 12:39 PM
RE: Pointer in Basic - by SMcNeill - 07-18-2023, 04:13 PM
RE: Pointer in Basic - by Kernelpanic - 07-18-2023, 04:26 PM
RE: Pointer in Basic - by SMcNeill - 07-18-2023, 04:59 PM
RE: Pointer in Basic - by SagaraS - 07-18-2023, 04:49 PM
RE: Pointer in Basic - by SMcNeill - 07-18-2023, 05:04 PM
RE: Pointer in Basic - by mnrvovrfc - 07-18-2023, 08:15 PM
RE: Pointer in Basic - by SagaraS - 07-18-2023, 07:30 PM
RE: Pointer in Basic - by SMcNeill - 07-18-2023, 10:11 PM
RE: Pointer in Basic - by SagaraS - 07-19-2023, 10:27 AM
RE: Pointer in Basic - by SMcNeill - 07-19-2023, 01:42 PM
RE: Pointer in Basic - by DSMan195276 - 07-19-2023, 11:15 PM



Users browsing this thread: 4 Guest(s)