Old 08-30-2009, 11:37 PM   #1
whatsup
Human being with feelings
 
whatsup's Avatar
 
Join Date: Aug 2008
Posts: 1,144
Default a memory allocation question

for example this code
Code:
 a = 0;
 b = 1;
 a[1] = 2;
what i understand, that a located at memory address 0 , and a[1] at memory address 1 (*8 because it's 64 bit number)

but what about b, i think that it located after a, at adrees 1.

so a[1] and b located at the same address !

is that correct ?
__________________
you can contack me on
whatsup@inn.co.il
whatsup is offline   Reply With Quote
Old 08-31-2009, 04:21 AM   #2
Jonas_Eriksson_Swe
Human being with feelings
 
Jonas_Eriksson_Swe's Avatar
 
Join Date: Jan 2007
Location: Umeå, Sweden
Posts: 947
Default

No, I don't think they're at the same location. This is from an old thread (I made the important line for this question bold):

Quote:
Originally Posted by dsilver View Post
There is no difference between the statements

buffer = 1024;
and
x = 5;

in that each one creates a local variable and initializes it.

It is the act of putting square brackets after one of these variables that turns the variable into a pointer, i.e. makes it operate by reference.

So, buffer[0] references the value stored at the 1024th location in local memory. And buffer[1], buffer[2] reference subsequent values. But there is nothing special about the variable "buffer".

So when the docs say:
buffer = 1024; // set buffer to reference the local memory starting at 1024

I think this is misleading. "buffer" isn't being set to reference memory starting at 1024 any more than every other statement which creates and initializes a variable, such as "x = 5;" sets that variable to "reference memory starting at location whatever (in this case 5)."

The fact is that any variable can be used as a pointer into local memory if [] is put after it. So if "buffer" happens to be set the VALUE 1024, then buffer[0] is essentially the same as 1024[0].

All in all it's very handy and very simple. But I think the docs should make clear that there is no special voodoo going on in the buffering example. It is also important to realize that the space which is allocated for the variables themselves, i.e. "buffer", "x", etc. is allocated elsewhere. So one is free to use any location one wants to use within local memory.

So, looking at each of the following lines individually,

1000[1] = 6;
1[1000] = 6;
x = 500; x[501] = 6;
y = 501; y[500] = 6;
buffer = 1001; buffer[0] = 6;
buffer = 1000; buffer[1] = 6;
buffer = 0; buffer[1001] = 6;

All of them do the EXACT same thing with regard to memory location 1001.

"x" and "y" and "buffer" are just variables which can be used in any way variables can be used.

Sorry if this seems all too obvious, but if I can help clear up confusion for someone I think it is worth it.
Regards,
- Jonas

Last edited by Jonas_Eriksson_Swe; 08-31-2009 at 04:34 AM. Reason: Found the old thread
Jonas_Eriksson_Swe is offline   Reply With Quote
Old 08-31-2009, 05:20 AM   #3
whatsup
Human being with feelings
 
whatsup's Avatar
 
Join Date: Aug 2008
Posts: 1,144
Default

that's exactly what i thought.

that's why i wrote
Code:
 a = 0;
 b = 5;
 a[1] = 5;
you see the address a[1] is the value of a+1 = 0 + 1 = 1;

but after a, var b is located.
so what i think is like that:
the first var unless it doesn't have an address (a=1024)
located at address 0
the second located at adress 1, etc..

so in my example

a stored at address 0
b stored at address 1

a[1] = 0[1] = 1 = address of b

isn't it ?


EDIT: in other words, my question can be.

what address b is located ?
__________________
you can contack me on
whatsup@inn.co.il

Last edited by whatsup; 08-31-2009 at 05:34 AM.
whatsup is offline   Reply With Quote
Old 08-31-2009, 05:36 AM   #4
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 10,028
Default

Code:
 a = 0;
 b = 1;
 a[1] = 2;
Correct. a[1]=2 is equivalent to b[0]=2. The value of b remains 1, but the value stored in the first memory slot becomes 2.
schwa is offline   Reply With Quote
Old 08-31-2009, 06:31 AM   #5
whatsup
Human being with feelings
 
whatsup's Avatar
 
Join Date: Aug 2008
Posts: 1,144
Default

Quote:
Originally Posted by schwa View Post
Code:
 a = 0;
 b = 1;
 a[1] = 2;
Correct. a[1]=2 is equivalent to b[0]=2. The value of b remains 1, but the value stored in the first memory slot becomes 2.
thank you very very much.
that's what i thought when i saw bugs in some effects .

EDIT: just to make it more clear. this is correct also if using var b with no brackets ?
in any case var b in this example located at memory slot 1

because my problem is
if i give an array address 0 - a=0
then it overlap all above vars, yes ?

a = 0;
b= something;
c= something;

in that example , b,c use the same memory slot as a[1],a[2] ?
__________________
you can contack me on
whatsup@inn.co.il

Last edited by whatsup; 08-31-2009 at 06:40 AM.
whatsup is offline   Reply With Quote
Old 08-31-2009, 10:09 AM   #6
Jeffos
Mortal
 
Jeffos's Avatar
 
Join Date: Dec 2008
Location: France
Posts: 1,969
Default

whatsup, you again! you're everywhere
Quote:
Originally Posted by whatsup View Post
EDIT: just to make it more clear. this is correct also if using var b with no brackets ?
in any case var b in this example located at memory slot 1
no: see the sentence Jonas has bolded... From our mortal point of view, variables are not part of the local buffer, they're stored "elsewhere" and brackets are required to access that buffer (simple variable otherwise).
Jeffos is offline   Reply With Quote
Old 08-31-2009, 10:43 AM   #7
whatsup
Human being with feelings
 
whatsup's Avatar
 
Join Date: Aug 2008
Posts: 1,144
Default

Quote:
Originally Posted by Jeffos View Post
variables are not part of the local buffer, they're stored "elsewhere" and brackets are required to access that buffer.
if that's so, evreything's fine.
so where are they placed ?
in the manual it explained that there are only to memory areas, local/global.
__________________
you can contack me on
whatsup@inn.co.il
whatsup is offline   Reply With Quote
Old 08-31-2009, 01:23 PM   #8
Mich
Human being with feelings
 
Join Date: May 2009
Posts: 1,265
Default

From my experience JS works like this: variables, local memory and global memory (via gmem[]) are all separate.

a,b,c,whatever,foo,bar,foobar etc are all variables.
Putting square brackets behind a variable (or even number) will access the local memory at the address that is calculated as follows:
a[b] = access element at address slot (a+b)
0[1] = slot 0+1=1
foo[0] = slot foo+0 = foo
(foo+x)[0] = slot foo+x+0
It also works despite a white space e.g.:
foo [x] = foo+x
( 10 * 30 ) [t] = 10*30+t

I think you get the idea.

Every effect has its own local memory (about 8e6 slots as far as I remember). Those are accessed as explained above.

Then there is global memory shared with all effects. I think this is now actually per chain or something, anyway it is a relict from the JesuSonic effects processor where you only had ONE chain in it. Anyway those are also 8e6 slots and those are accessed via gmem[var].

Hope that helps.
Mich is offline   Reply With Quote
Old 08-31-2009, 02:05 PM   #9
whatsup
Human being with feelings
 
whatsup's Avatar
 
Join Date: Aug 2008
Posts: 1,144
Default

Quote:
Originally Posted by Mich View Post
From my experience JS works like this: variables, local memory and global memory (via gmem[]) are all separate.

Hope that helps.
yes a lot.
that what i've been missing, i didn't know where the simple vars allocated.
so now i understand that they have their own area,
not sharing their area with arrays.

edit: but as i said, this looks little strange, where can they be stored.
so i'd like very much, schwa, to sort that.
__________________
you can contack me on
whatsup@inn.co.il

Last edited by whatsup; 08-31-2009 at 02:08 PM.
whatsup is offline   Reply With Quote
Old 09-01-2009, 12:15 AM   #10
Jeffos
Mortal
 
Jeffos's Avatar
 
Join Date: Dec 2008
Location: France
Posts: 1,969
Default

Quote:
Originally Posted by Mich View Post
Then there is global memory shared with all effects. I think this is now actually per chain or something, anyway it is a relict from the JesuSonic effects processor where you only had ONE chain in it. Anyway those are also 8e6 slots and those are accessed via gmem[var].
gmem is really global (cross chains, cross tracks, etc...)
Jeffos is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:00 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.