Reputation: 1367
I am writing a server-side application using JavaScript (Express). So I have to validate one big stream of chars (base 64 string). I kinda know what I want to do and how but I have performance related question.
Consider that the string that is uploaded is really big (up to 5 MB). I have already written couple of functions that should do the validation but I am not aware of what is going on behind the hood.
function validate(str) {
....
return bool;
}
var b64_string = '......'; // <- string can be 5 megabytes
if(validate(b64_string) {
doSomething(b64_string);
}
If this was C a stack would be allocated for validate(str) function and there would be 5mb of memory for passed variable.
But what happens in JavaScript engine? Is there any way of sending 'pointer' to function so memory consumption does not get too big? T
Thanks in advance!
Upvotes: 0
Views: 46
Reputation: 146310
objects in javascript are passed by reference.
I believe integers and strings (etc) are not, so be careful of that point.
Consider adding your string to an object hash reference which you can then pass by reference down the chain.
for example:
var hashRef = {};
hashRef.b64_string = '......'; // <- string can be 5 megabytes
function validate(hashRef) {
....
return bool;
}
if(validate(hashRef)) {
doSomething(hashRef);
}
Upvotes: 2