Creating bytes collection in old browsers through Javascript?

Asked

Viewed 42 times

2

I wonder if there’s such a thing as Uint8Array in older browsers (at least IE8), a collection type with elements that occupy only 1 byte of browser memory.

An approach would be to use strings, however, as far as I know, browsers use UTF-16 encoding that uses 2 (or more, I think) bytes for each character.

On the moon, for example, something that would help create something like Uint8Array would be a string (there, each character of a string is 8 bits). But a string has to be recreated to be modified, so I don’t think it’s a good idea.

P.S.: The Cheat Engine (or some similar tool) can help to view the browser memory. Below is a fixed byte list created by an instance of U\u{69}nt8Array.

Memória

So, is there any way to do this at least on IE8, through Javascript (or in combination with Vbscript)? Bytes from this collection will have to be modified occasionally.

1 answer

3


Javascript is probably not the most suitable language for this. It wasn’t designed to minimize memory usage and make your access more flexible. Now they’re including a little bit of this kind of thing.

What you can do, but it’s a tremendous gambit, is to use string same and put two dice in each character since the JS is specified to use UTF-16. You have to create a library to make this composition and access it the way you want. The most you’ll have to waste is a byte if you have an odd number of elements.

You can do with the numeric type as well, although it’s a slightly more difficult composition to make. I would have to analyze all the implications, I don’t know if it’s such a good idea to put in a array depending on the engine of the JS used.

Given the difficulties, I would say that it is better to give up this or the requirement to work in old browsers.

  • I agree. My idea of doing this in the language no longer suitable was to transpose Lua to a type of data collection that would be computed by Javascript, thus becoming a transpilation of Lua to Javascript, without having to interpret Lua again in Javascript. I want this more because of performance. However, if Uint8Array is not supported, I can still add a polyfill + a warning (or something typical) saying that it would be better to use a current browser. Vlw for the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.