SenasOzys has quit [Remote host closed the connection]
Praetonus has quit [Quit: Leaving]
sarna has joined #ponylang
vaninwagen has quit [Ping timeout: 256 seconds]
<dougmacdoug>
is there a way to determine how much space an array is using? .. made an class with no member data, created an array and pushed 2 on the array but a[0] isnt a[1] .. which lead me to believe the array i an array of pointers instead of packed like an array of c structs
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
sternmull has quit [Quit: Leaving.]
<strmpnk>
I think objects that have descriptors (classes, primitives) are allocated as references rather than intrusively. Structs (and tuples) should be flat in the array IIRC.
<strmpnk>
Part of the intuition I have here is that a reference to an entry can outlive the array. You'd want the array to be collected. Structs are a kind of immediate value (or at least that's what I call it) so they really only exist as values (the address exists too but only for FFI calls).
<dougmacdoug>
i think arrays allocate space for pointers with structs too
<strmpnk>
I'm not sure that's the case for the FFI calls I've seen. Could be wrong I guess but C would depend on flattening here.
SenasOzys has joined #ponylang
kubesys has quit [Remote host closed the connection]
kubesys has joined #ponylang
<dougmacdoug>
c might but if you create a struct and push it onto a pony array the array stores a pointer
<dougmacdoug>
or seems to
<SeanTAllen>
what is "how much space an array is using" dougmacdoug ? I believe we talked about something similar to this before. I'm assuming this is different than that previous converstion.
<dougmacdoug>
I am trying to use less memory holding an array of objects.. i thought I could use structs but seems to be same results as using class instances... (for example a class with only 2 U8 members)
<SeanTAllen>
sorry, i dont really understand.
<SeanTAllen>
"less memory holding an array of objects" is rather vague. less memory used for what exactly?
<dougmacdoug>
in C if you have an array of structs and the struct has 2 members 1 byte each, each element of the array takes 2 bytes * n elements
<strmpnk>
The C ABI determines structure packing and alignment for compatibility and direct field pointer dereference safety. Have you tried adding \packed\ to the struct?
<SeanTAllen>
dougmacdoug: i am aware of that, doesn't help me understand your question
<dougmacdoug>
so my question is., can I make a similar array in pony or am I required to make an array with a pointer plus the 2byte element for each element
<SeanTAllen>
sorry, what is "similiar array"?
<dougmacdoug>
an array of structs..
<SeanTAllen>
i dont really understand your question because you are talking in terms of C
<SeanTAllen>
sorry, im just not following what you are asking
<SeanTAllen>
going all the way back to a[0] isnt a[1]
<dougmacdoug>
I just want to make a very large array using as little memory as possible.. each element is smaller than a 64 bit pointer.. so I dont want to have the element data plus the 64 bit pointer for every item in the array
<SeanTAllen>
or for that matter what you are definiing as the amount of space an array is using
khan has quit [Quit: khan]
<SeanTAllen>
what type are these small objects?
khan has joined #ponylang
<SeanTAllen>
is it an Array[U8] ?
<SeanTAllen>
Array[U32]?
<SeanTAllen>
Array[Foo] ?
<dougmacdoug>
well, i was trying to use Array[Foo] where Foo is a struct with u8
<SeanTAllen>
why?
<SeanTAllen>
why not just an Array[U8] ?
<dougmacdoug>
well, i could do that but the U8 is encoded and I have a class that uses it with methods.. so I can pop U8s off and the wrap them and thats ok, but then I still get a bunch of intermediate instances
<SeanTAllen>
sorry, i dont really follow.
<SeanTAllen>
i think what you are asking, in a roundabout way is how you can control the memory layout. is that correct?
<strmpnk>
dougmacdoug: You're asking for the Pony equivalent of the `(struct T)[N] foo;`?
jemc has joined #ponylang
Praetonus has joined #ponylang
<dougmacdoug>
i guess I will just use builtin numbers and move all my convenience code a primitive
<strmpnk>
I should use a real C code example but the idea of compacting the array to hold a flat set of bytes, where N entries take N*(sizeof struct) bytes, in this case N*2 + the fixed array field and descriptor overhead?
<dougmacdoug>
just to make it super simple, in C if I made a 2 element array of 1 byte structs, the pointer to the first element is 0x10 then the pointer to the next element is 0x11 and there is no other 64bit pointers created anywhere.. this does not seem to be so in pony..
<strmpnk>
Okay. The pointers won't be exposed for safety and guarantee reasons but you should be able to get that flat memory. How are you measuring this?
<dougmacdoug>
I was getting the digests of the structs
<SeanTAllen>
To be clear. Pony does not have structs. There is struct but it is only to be used for C-FFI compatability. You seem to be wanting to use it for an entirely different purpose.
<dougmacdoug>
but I think the answer is just to use primitive numerics
<SeanTAllen>
machine words are stored inline in the array
<SeanTAllen>
a
<SeanTAllen>
Array[Foo] is an entirely different story
khan has quit [Quit: khan]
<dougmacdoug>
ok.. I'll just bit encode and use primitives..
khan has joined #ponylang
<SeanTAllen>
ok, im still not sure what you are trying to do and what your data looks like exactly. it might be the right thing to do. sorry to not be more help dougmacdoug
dougmacdoug has quit [Ping timeout: 260 seconds]
jemc has quit [Ping timeout: 240 seconds]
codec1 has quit [Read error: Connection reset by peer]
Praetonus has quit [Ping timeout: 240 seconds]
sarna has quit [Quit: Connection closed for inactivity]
Praetonus has joined #ponylang
enilsen16 has joined #ponylang
SenasOzys has quit [Remote host closed the connection]
SenasOzys has joined #ponylang
SenasOzys has quit [Remote host closed the connection]