Old 10-14-2018, 03:25 AM   #1
Human being with feelings
Join Date: Jun 2017
Posts: 135
Default JS array management

JS sucks! mainly because it lets the programmer shoot himself a lot.

JS definitely needs array management. By not managing allocation it is very easy to overright data. JS is already hard enough to debug(specially when the debugger craps out and stops updating values or requires one to run the script for sliders to update values).

A solution could be done in a library by writing a simple memory manager that returns unallocated regions of memory but I won't do this because I plan on not writing anything else in JS since it is too much trouble.
InfiniteDimensionality is offline   Reply With Quote
Old 10-14-2018, 06:49 AM   #2
Human being with feelings
geraintluff's Avatar
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 278

Originally Posted by InfiniteDimensionality View Post
A solution could be done in a library by writing a simple memory manager that returns unallocated regions of memory
There have been at least a couple of implementations of this. I haven't used Tale's one, but their code generally looks good.

Personally, I just use a simple pattern like this in @init:
freemem = 0;

block1length = 3000; // or whatever
freemem = (block1buffer = freemem) + block1length;

// freemem now holds the next unallocated pointer, ready for block2
However, I assume from your extremely strong reaction that you have a whole litany of complaints against JS, not just this one issue with the memory block.

Given that, I'm not going to try and convince you why JS is wonderful - here are lots of other audio programming languages to try, and I believe many of them can be loaded as VSTs. Maybe one of those could work for you, although I wouldn't know what to recommend personally as I have been happily using JS for years.
geraintluff is offline   Reply With Quote
Old 10-14-2018, 08:45 AM   #3
Human being with feelings
TBProAudio's Avatar
Join Date: May 2014
Location: Germany
Posts: 445

Easy to use memory manager class.
Copy and paste code to memorymanager.jsfx-inc and and use as include in your JSFX code:

// Memory Manager Class
 // by TBProAudio 2014 (www.tb-software.com)
// - small memory manager class
// Usage:
// @init
//    MM.MemMgr_Init (0);
//  ...
//    buf0 = MM.MemMgr_Alloc(100);
//    buf1 = MM.MemMgr_Alloc(1000);

// Change log
// V1.0: First public release

desc: Memory Manager Class


// Small Memory Manager Class
function MemMgr_Init (start)
  this.pos = start;

// Use alloc where ever you want
function MemMgr_Alloc (cnt)
local (tmp)
    tmp = this.pos;
    this.pos += cnt;

// EO@init
TBProAudio is offline   Reply With Quote

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 09:45 PM.

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