Author Topic: Storing a static array in memory?  (Read 6156 times)

0 Members and 1 Guest are viewing this topic.

Offline denis mukhin

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +1/-0
    • View Profile
Storing a static array in memory?
« on: March 29, 2014, 10:11:29 pm »
I've been working on a raycaster in axe. I had it working with set x/y bounds, but I rewrote it on the computer (thanks clrhome.org IDE!) to get it working with some kind of map. It didn't work, and I found that the problem was with how I tried to store the map. So my question is how to store a defined series of constants in the memory? It can't be anything as simple as [10101010101]->L1, can it?

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: Storing a static array in memory?
« Reply #1 on: March 30, 2014, 03:04:51 am »
It is as simple as that. Square brackets take hex. If you want decimal values you can use data(). ;)

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Storing a static array in memory?
« Reply #2 on: March 30, 2014, 06:52:02 am »
It's nearly as simple as that. Just don't put →L1 since this pointer is already used, but something else like →°MyMap. Then you can do {A+°MyMap} the same way you would do {A+L1} :)

It is as simple as that. Square brackets take hex. If you want decimal values you can use data(). ;)
You can also have binary values using Data() by putting a π (pi) in front of your values ;)
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline denis mukhin

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +1/-0
    • View Profile
Re: Storing a static array in memory?
« Reply #3 on: March 30, 2014, 02:34:46 pm »

Thanks guys, but I have some questions...

It's nearly as simple as that. Just don't put →L1 since this pointer is already used, but something else like →°MyMap. Then you can do {A+°MyMap} the same way you would do {A+L1} :)
What do you mean by not using L1? I thought that L1 is a specific pointer to some free memory?
Also, what is "°MyMap"? I mean I'm aware I can name variable, but how would I define, for example, a portion of memory 16 bytes in size?
It is as simple as that. Square brackets take hex. If you want decimal values you can use data(). ;)
From what I can see on the axe parser command list, Data () adds bytes to the program memory? What does that mean? What is program memory in this case?


Maybe I'm just not getting this memory thing  :'(

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Storing a static array in memory?
« Reply #4 on: March 30, 2014, 02:46:47 pm »
What do you mean by not using L1? I thought that L1 is a specific pointer to some free memory?
Indeed, that's why you can't use it this way. L1 is already defined. You can't do whatever→L1. But you can do {whatever}→L1 whatever→{L1}, or Copy([101010101010],L1,6).

Also, what is "°MyMap"?
Seen from the program editor "°MyMap" is the "°" character followed with the "M" character... etc.
Seen from your program once compiled, it's a number. You just gave that number the name "°MyMap" because it's much more convenient to use.
Seen from the Axe Parser, it is a preprocessor name that means a number, it'll have to be replaced with that number at the end.
Seen from you, it's the pointer to what's before the "→".

Also, what is "°MyMap"? I mean I'm aware I can name variable, but how would I define, for example, a portion of memory 16 bytes in size?
It depends on what you call define. You can "create" 5 bytes of memory but just writing [0000000000] or Data(0,0,0,0,0) or Buff(5). Then you need a pointer to that so you can use those bytes, so you'll write → followed with a pointer. Note that doing this always works if you are only reading bytes, but if you compile as an app, you won't be able to write back to those bytes.
Alternatively, you can just use existing memory, like the area pointed by L1 or L2, or any free RAM area (or a non-free RAM area but maybe you won't be able to use your calculator afterwards).

From what I can see on the axe parser command list, Data () adds bytes to the program memory? What does that mean? What is program memory in this case?
Your program is just a bunch of bytes. Some of them are commands, some others are data, but it's just a pack of bytes. Data just adds some bytes in your program that you'll use as data. But if you mess up severely, you might be able to read or write data in the middle of your code and execute your data as if it was code :P
« Last Edit: March 30, 2014, 04:06:59 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Storing a static array in memory?
« Reply #5 on: March 30, 2014, 03:03:14 pm »
You can't do whatever→L1. But you can do {whatever}→L1
You mean whatever->{L1} of course.

Offline denis mukhin

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +1/-0
    • View Profile
Re: Storing a static array in memory?
« Reply #6 on: March 30, 2014, 03:12:40 pm »
Okay! I think I get the idea! I made a small test program and it works! Big respect! But I have a few more questions...
Seen from the program editor "°MyMap" is the "°" character followed with the "M" character... etc.
Seen from your program once compiled, it's a number. You just gave that number the name "°MyMap" because it's much more convenient to use.

Is the "°" character needed to properly define this pointer? Cause without it, I get an UNDEFINED error. I can't find the character itself in the documentation...

It depends on what you call define. You can "create" 5 bytes of memory but just writing [0000000000] or Data(0,0,0,0,0) or Buff(5). Then you need a pointer to that so you can use those bytes, so you'll write → followed with a pointer. Note that doing this always works if you are only reading bytes, but if you compile as an app, you won't be able to write back to those bytes.

So if I use a large ( but not too large ) amount of bytes when doing something like Data (1,2,3, ... ,256), it will still be able to allocate the memory for that? Also, what do you mean by not being able to write back to those bytes if I compile as an app? Is this app-specific?

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: Storing a static array in memory?
« Reply #7 on: March 30, 2014, 03:14:10 pm »
That sounds clear enough but you made a mistake in the first section. It's not {whatever}->L1 as that would try to override the compiler constant L1 with the value at address whatever. :P Not gonna happen. So the correct code is whatever->{L1}. ;)
Whoops :ninja:

So to your new post.
1) Yes it is needed. It is incompletely documented in the Basic Math section as °VAR. It basically defines a pointer or a constant (which are the same thing but used differently) when used with Sto-> and is used to access it when needed.
2) Apps are stored in flash memory which is read only for the most part. So it is app specific as programs run from RAM. If you use a shell to run them from archive they will be copied to RAM for execution and then archived back. This means that any data you change in your program is persistent across runs. This can be an interesting effect or very frustrating depending on the situation.
Also program memory is the program file itself. Anything you add increases the size of the program. But as long as you have enough RAM to run it you're fine. If you dynamically allocate memory however then it's another story.
« Last Edit: March 30, 2014, 03:23:42 pm by Streetwalrus »

Offline denis mukhin

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +1/-0
    • View Profile
Re: Storing a static array in memory?
« Reply #8 on: March 30, 2014, 03:28:35 pm »
Okay thanks everybody! I'll try to apply this to the raycaster later today and hope that it will work!

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Storing a static array in memory?
« Reply #9 on: March 30, 2014, 04:06:33 pm »
You can't do whatever→L1. But you can do {whatever}→L1
You mean whatever->{L1} of course.
That sounds clear enough but you made a mistake in the first section. It's not {whatever}->L1 as that would try to override the compiler constant L1 with the value at address whatever. :P Not gonna happen. So the correct code is whatever->{L1}. ;)
Whoops :ninja:
Fail. Thanks :)
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: Storing a static array in memory?
« Reply #10 on: March 30, 2014, 04:10:56 pm »
Okay thanks everybody! I'll try to apply this to the raycaster later today and hope that it will work!
You're very welcome ! :) I wish you luck with your project.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Storing a static array in memory?
« Reply #11 on: March 30, 2014, 04:14:07 pm »
Yeah good luck :) raycasters are always great to watch running :w00t: