BBC BASIC for Windows
« Memory Management »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:10pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Memory Management  (Read 660 times)
Kirkkaf13
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 28
xx Memory Management
« Thread started 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.
User IP Logged

rtr2
Guest
xx Re: Memory Management
« Reply #1 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:
  • Many Windows API calls require the address of a variable to be passed as a parameter.

  • It can be useful in assembler code, for example when loading a register from a variable: mov eax,[^var%].

  • It was necessary to allow emulation of the VARPTR() function available in several other dialects, such as QBASIC.
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.
User IP Logged

Kirkkaf13
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 28
xx Re: Memory Management
« Reply #2 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
« Last Edit: Apr 26th, 2015, 3:55pm by Kirkkaf13 » User IP Logged

rtr2
Guest
xx Re: Memory Management
« Reply #3 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.
« Last Edit: Apr 26th, 2015, 5:03pm by rtr2 » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls