BBC BASIC for Windows
Programming >> BBC BASIC language >> Memory Management
http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1429821833

Memory Management
Post by Kirkkaf13 on Apr 23rd, 2015, 8:43pm

Hello,

I am interested in learning more about how computers and applications use memory and how I can use BBC Basic to manage my applications using the Indirection operators within the 'heap'.

My current understanding is binary is; it is measured in bits. Each 1/0 is a bit and 8 bits make a byte.

A CHAR in C is 8 bits / 1 byte; 11111111 would present 255.

As this is RAM (Random Access Memory) the system then allocates a random unique memory access to the variable. This can directly be accessed with ^ in BBC Basic?

What I am struggling to understand is, why I would need to know the memory address, what I can do with it and how the indirection operators work as I do not fully understand the manual.

Please let me know if I am not precise enough with my question and I will attempt to clarify.

I feel I need to get a good understand of this before concentrating on the windows API.

Thank you.
Re: Memory Management
Post by rtr2 on Apr 23rd, 2015, 10:25pm

on Apr 23rd, 2015, 8:43pm, Kirkkaf13 wrote:
What I am struggling to understand is, why I would need to know the memory address

Only very rarely, as is evidenced by the fact that no other version of BBC BASIC supports the 'address of' operator! I added it in BB4W for three main reasons:
In the context of "learning more about how computers and applications use memory" you could use the address-of operator to allow you to examine the makeup of a variable. For example this code lists the ten hexadecimal bytes which make up the value of PI:

Code:
      mypi = PI
      a% = ^mypi
      FOR i% = 0 TO 9
        PRINT ~a%?i%
      NEXT 

Richard.
Re: Memory Management
Post by Kirkkaf13 on Apr 26th, 2015, 3:48pm

Hello Richard,

Thank you for providing the example.

I have a few further questions;

How did you know the value of PI would return 10 bytes? I thought floating point numbers in BBC BASIC was 32bit/4bytes (using V5)?

How can I see the binary representation of PI to understand how floating point numbers look in binary?

Thank you,

Kirk
Re: Memory Management
Post by rtr2 on Apr 26th, 2015, 4:52pm

on Apr 26th, 2015, 3:48pm, Kirkkaf13 wrote:
How did you know the value of PI would return 10 bytes? I thought floating point numbers in BBC BASIC was 32bit/4bytes (using V5)?

Native floating-point numbers in BBC BASIC are never 4 bytes (not even in the original 6502 version); you must be thinking about a different dialect of BASIC. In BBC BASIC they are either 5, 8 or 10 bytes. In this case I was using v6.00a, so variant numeric variables are 10 bytes (unless I state otherwise, you should assume that I am using the latest version).

Quote:
How can I see the binary representation of PI to understand how floating point numbers look in binary?

It's documented in the BB4W help manual, under 'Format of Data in Memory... Variable storage in memory', or you can read it online here.

Richard.