-
Notifications
You must be signed in to change notification settings - Fork 96
Open
Labels
Description
This sounds like multiple issues but they are all related. For the following js code:
var s = "";
for (var i = 0; i < 10000; ++i) {
s += i;
}
console.log(s.length);
- The output of the compiled c code is
-26646
. - If 10000 gets changed to 100000...
Assertion 'gc_main->data != NULL' failed.
...
Both these issues are because int16_t
is used (aka short
) which is obviously not enough.
- However, if something like
unsigned long
is used, too many allocations will be done and from my experience my system (Arch Linux with 8gb of ram) froze...
I think a solution to this will be first using a something like size_t
instead of int16_t
. Using size_t
is better I guess so that the compiler deals with it and 16-bit microcontrollers stay happy (issue #41).
Then, a better mini string implementation should be done. Many libraries already exist out there. Also C++ implementation does pretty well which I assume can be cloned to C. The following works pretty well:
int main() {
string s = "";
for (int i = 0; i < 1000000; ++i) {
s += to_string(i);
}
cout << s << endl;
}