Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Length is set to 1 but size is three #13

Open
ztamizzen opened this issue Oct 14, 2016 · 8 comments
Open

Length is set to 1 but size is three #13

ztamizzen opened this issue Oct 14, 2016 · 8 comments

Comments

@ztamizzen
Copy link

I create a ArrayType('float') then instantiate it with size of 1, when I debug it it has three positions but the length is set to 1.
This results in when I run .toArray on it I only get one back. This might sound correct but for some reason the value I wan't is at idx three and does not get returned.

let testArrayType = ArrayType('int'),
    testArray = new testArrayType(1);
 console.log(testArray);

the above results in:

ArrayType {buffer: Buffer[4], __length: 1}
0: 0
1: 0
2: 0
__length: 1

Which does not make sense.
I am using electron, if that matters.

@TooTallNate
Copy link
Owner

TooTallNate commented Oct 14, 2016

I can't reproduce:

$ cat t.js
const ArrayType = require('./');

let testArrayType = ArrayType('int'),
  testArray = new testArrayType(1);

console.log(testArray);

$ node t
[ 0, buffer: <Buffer@0x104033838 00 00 00 00> ]

@ztamizzen
Copy link
Author

ztamizzen commented Oct 15, 2016

Tried it at home and got
[ -1950620320, buffer: <Buffer@0x00000178C3B872D0 60 e5 bb 8b> ]
which is a bit odd but at least it's just one position in the array.

So I guess there is something wrong with my setup at work.

@ztamizzen
Copy link
Author

Why is yours 0 but I get a lot of garbage?...

@TooTallNate
Copy link
Owner

TooTallNate commented Oct 15, 2016

What version of Node are you using? Buffer zero-fills by default now IIRC (I'm using latest 6.x version).

@ztamizzen
Copy link
Author

ztamizzen commented Oct 15, 2016

v6.3.0
Just upgraded and it looks more sensible.
Thank u, u can close this. I'll need to fix my setup at work.

@TooTallNate
Copy link
Owner

Well we're using different versions of ref as well, which is evidenced by the fact that your Buffer inspected object has prefixed 000 chars in the memory address. I removed those at one point.

@TooTallNate
Copy link
Owner

Actually nvm, I guess they're not zero-filled by default at this point (I'm on v6.6.0):

> new Buffer(1000)
<Buffer 05 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 46 05 02 01 00 00 00 0a 00 00 00 00 00 00 00 78 46 05 02 01 00 00 00 05 00 00 00 01 00 00 00 00 00 ... >

So the fact that you got a random number is just a coincidence.

@ztamizzen
Copy link
Author

I've got the latest from npm, do I need to add @latest to it?...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants