Cockos Incorporated Forums a memory allocation question
 Register Track Bugs/Feature Requests Search Today's Posts Mark Forums Read

 08-30-2009, 11:37 PM #1 whatsup Human being with feelings     Join Date: Aug 2008 Posts: 1,144 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
08-31-2009, 04:21 AM   #2
Jonas_Eriksson_Swe
Human being with feelings

Join Date: Jan 2007
Location: Umeå, Sweden
Posts: 947

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 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

 08-31-2009, 05:20 AM #3 whatsup Human being with feelings     Join Date: Aug 2008 Posts: 1,144 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.
 08-31-2009, 05:36 AM #4 schwa Administrator     Join Date: Mar 2007 Location: NY Posts: 10,028 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.
08-31-2009, 06:31 AM   #5
whatsup
Human being with feelings

Join Date: Aug 2008
Posts: 1,144

Quote:
 Originally Posted by schwa 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.

08-31-2009, 10:09 AM   #6
Jeffos
Mortal

Join Date: Dec 2008
Location: France
Posts: 1,969

whatsup, you again! you're everywhere
Quote:
 Originally Posted by whatsup 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).

08-31-2009, 10:43 AM   #7
whatsup
Human being with feelings

Join Date: Aug 2008
Posts: 1,144

Quote:
 Originally Posted by Jeffos 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

 08-31-2009, 01:23 PM #8 Mich Human being with feelings   Join Date: May 2009 Posts: 1,265 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.
08-31-2009, 02:05 PM   #9
whatsup
Human being with feelings

Join Date: Aug 2008
Posts: 1,144

Quote:
 Originally Posted by Mich 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.

09-01-2009, 12:15 AM   #10
Jeffos
Mortal

Join Date: Dec 2008
Location: France
Posts: 1,969

Quote:
 Originally Posted by Mich 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...)

 Thread Tools Display Modes Linear Mode

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home General Discussion     General Discussion (aka spam trap) REAPER Forums     REAPER General Discussion Forum     newbieland     REAPER Q&A, Tips, Tricks and Howto     Recording Technologies and Techniques     REAPER Compatibility     REAPER Color Themes and Icon Sets     MIDI Hardware, Control Surfaces, and OSC     REAPER Non-English Speaking User Forums         Forum de REAPER en français         Foro de REAPER en Español         Fórum do REAPER em português         Forum di REAPER in italiano         Deutschsprachiges REAPER Userforum         Pyccкоязычный фopyм REAPER     REAPER Bug Reports     REAPER Feature Requests     Dstruct's Casa De Nitpicks     REAPER for Live Use     REAPER for Video Editing/Mangling     REAPER for Ambisonic and 3D positional audio uses     ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum     REAPER for macOS X     REAPER for Linux     REAPER Pre-Release Discussion     REAPER Music/Collaboration Discussion     REAPER lounge NINJAM Discussion     NINJAM User Discussion     NINJAM Developer Discussion Other Software Discussion     WDL users forum     LICEcap Discussion     OSCII-bot forum     Old Cockos Products Forum

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

 -- Cockos ---- REAPER 5 ---- Reaper 3 ---- Reaper 2 ---- Reaper 1 Contact Us - Çockos Incorporated - Archive - Top