Old 09-21-2017, 04:42 PM   #1
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 1,638
Default Use of memset.

The JS documentation reads:

'memset(dest,value,length)
The memset() function provides the ability to quickly set a region of the local memory buffer to a particular value.'

I assume that 'dest' is the number of the first item of memory and 'length' is the number of items, is that correct? So e.g. if I want to set a block of memory samplesblock long starting from zero to a value of -1, my code should read memset(0,-1,samplesblock)?
__________________
Mal, aka The Wasters of Time
Mal's JSFX: ReaRack2 Modular Synth
Time Waster is offline   Reply With Quote
Old 09-21-2017, 10:32 PM   #2
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
Default

Quote:
Originally Posted by Time Waster View Post
I want to set a block of memory samplesblock long starting from zero to a value of -1, my code should read memset(0,-1,samplesblock)?
???

if samplesblock is an "array", in JSFX-Speak meaning that you do something like "sampleslock = 987;" to locate it somewhere in the JSFX instances local memory and then can access it's elements by e.g. samplesblock[0], samplesblock[1], ... and the memory you need for sampleblock is 100 elements, you would do "memset(samplesblock, -1, 100);"

-Michael
mschnell is offline   Reply With Quote
Old 09-21-2017, 11:30 PM   #3
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 1,638
Default

Maybe not a good example. 'samplesblock' is a special variable (read only) which provides the number of samples per block. So it's just a number, not an array.

I was assuming that 'dest' would point to the first item in memory and 'length' would refer to the last item, and that those items and all the items in between would be set to 'value'. By your explanation, 'dest' would refer to a block of memory, but then how would you locate the block and why have the 'length' argument? The documentation is not very clear, a simple example would have helped.
__________________
Mal, aka The Wasters of Time
Mal's JSFX: ReaRack2 Modular Synth
Time Waster is offline   Reply With Quote
Old 09-22-2017, 06:04 AM   #4
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
Default

This is just how arrays work in EEL .

There is just one "array" of local memory. (Another one is "global".)

If you want to use multiple arrays, you need to select a number for each of them determining the starting point (element number) of same.

For convenience you write that number in a variable (say "a", a = 80).

Now most conveniently you access element number "i" say i = 9 in your array as "a[i]"

But you also could write 80[9], 0[a+i], (a+i)[0], 0[89], 89[0], ...

-Michael (sorry for being fooled regarding "sampleblock")
mschnell is offline   Reply With Quote
Old 09-22-2017, 06:29 AM   #5
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 1,638
Default

Well, whatever I'm doing, it seems to be working for now.
__________________
Mal, aka The Wasters of Time
Mal's JSFX: ReaRack2 Modular Synth
Time Waster is offline   Reply With Quote
Old 09-22-2017, 11:31 AM   #6
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
Default

Quote:
Originally Posted by Time Waster View Post
if I want to set a block of memory samplesblock long starting from zero to a value of -1, my code should read memset(0,-1,samplesblock)?
Yes, that's correct.
IXix is offline   Reply With Quote
Old 09-23-2017, 07:52 AM   #7
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 1,638
Default

Thanks IXix!
__________________
Mal, aka The Wasters of Time
Mal's JSFX: ReaRack2 Modular Synth
Time Waster is offline   Reply With Quote
Old 09-24-2017, 05:46 AM   #8
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
Default

Quote:
Originally Posted by IXix View Post
Yes, that's correct.
Quick warning. If you're using samplesblock like that you should be aware that (IIRC) the value of samplesblock is zero until the first @block happens. That has caught me out a couple of times.
IXix is offline   Reply With Quote
Old 09-24-2017, 11:36 PM   #9
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 1,638
Default

I have been caught out by that myself when trying to use samplesblock @slider.
__________________
Mal, aka The Wasters of Time
Mal's JSFX: ReaRack2 Modular Synth
Time Waster is offline   Reply With Quote
Old 09-25-2017, 02:42 AM   #10
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
Default

Quote:
Originally Posted by Time Waster View Post
I have been caught out by that myself when trying to use samplesblock @slider.
Rite of passage.
IXix 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 08:20 AM.


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