There is one thing that I've been meaning to ask for a long time now.
I see most of the people tend to create arrays in C by malloc/___alloc_rc and then assigning values by iterating over them via a setter function (also defined with c-lambda). Isn't there a way to directly do this with a memcpy operation? Wouldn't that be faster?
I understand that Gambit's heap and C's heap are separate, and you need to copy from one another in order to avoid GC touching any of FFI-created memory. But is it possible to improve this process using some sort of C function/macro from Gambit?
I really can't find any code examples or reference for this.
Thank you very much.
Álvaro
Afficher les réponses par date
Hi Alvaro,
You can traverse all Scm structures from C.
You have typecheckers, car, cdr, vector-ref, accessors for all the specialized vector types and so on.
In the current Gambit version, from all I know, using these works perfectly.
As soon as Gambit goes SMP, this may be a slightly other story and only the objects specifically allocated with ___STILL may be safe to use, we'll see when we get there. What could be an issue would be that the GC would trig during your C call and change all the other object references to an object and then its physical memory location, and you'd be using the old one in your C code.
Do you have a specific question or problem to solve?
Brgds, Mikael
2013/4/12 Álvaro Castro-Castilla alvaro.castro.castilla@gmail.com
There is one thing that I've been meaning to ask for a long time now.
I see most of the people tend to create arrays in C by malloc/___alloc_rc and then assigning values by iterating over them via a setter function (also defined with c-lambda). Isn't there a way to directly do this with a memcpy operation? Wouldn't that be faster?
I understand that Gambit's heap and C's heap are separate, and you need to copy from one another in order to avoid GC touching any of FFI-created memory. But is it possible to improve this process using some sort of C function/macro from Gambit?
I really can't find any code examples or reference for this.
Thank you very much.
Álvaro
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Thanks, Mikael.
If you use Car, Cdr, etc from C, you are actually at the same point, traversing the structure. That's fine for lists, but what about vectors? I would like to use memcpy, but for that: - i must respect alignment, padding or chunks if they happen to exist in Gambit's vectors implementation. - i must know the array pointer, in case is stored after some Gambit-specific data, such as type tags.
Thanks again for your answer,
Álvaro El 12/04/2013 12:37, "Mikael" mikael.rcv@gmail.com escribió:
Hi Alvaro,
You can traverse all Scm structures from C.
You have typecheckers, car, cdr, vector-ref, accessors for all the specialized vector types and so on.
In the current Gambit version, from all I know, using these works perfectly.
As soon as Gambit goes SMP, this may be a slightly other story and only the objects specifically allocated with ___STILL may be safe to use, we'll see when we get there. What could be an issue would be that the GC would trig during your C call and change all the other object references to an object and then its physical memory location, and you'd be using the old one in your C code.
Do you have a specific question or problem to solve?
Brgds, Mikael
2013/4/12 Álvaro Castro-Castilla alvaro.castro.castilla@gmail.com
There is one thing that I've been meaning to ask for a long time now.
I see most of the people tend to create arrays in C by malloc/___alloc_rc and then assigning values by iterating over them via a setter function (also defined with c-lambda). Isn't there a way to directly do this with a memcpy operation? Wouldn't that be faster?
I understand that Gambit's heap and C's heap are separate, and you need to copy from one another in order to avoid GC touching any of FFI-created memory. But is it possible to improve this process using some sort of C function/macro from Gambit?
I really can't find any code examples or reference for this.
Thank you very much.
Álvaro
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Well, by just digging into ___VECTOR_REF you'll get the translation from ___SCMOBJ to CPU heap location.
For special pointer types there's less worry about data unit sizes and so on; you just get the byte array's start offset and the (U|S)(8|16|32)vector contents follow in one block after this.
2013/4/12 Álvaro Castro-Castilla alvaro.castro.castilla@gmail.com
Thanks, Mikael.
If you use Car, Cdr, etc from C, you are actually at the same point, traversing the structure. That's fine for lists, but what about vectors? I would like to use memcpy, but for that:
- i must respect alignment, padding or chunks if they happen to exist in
Gambit's vectors implementation.
- i must know the array pointer, in case is stored after some
Gambit-specific data, such as type tags.
Thanks again for your answer,
Álvaro El 12/04/2013 12:37, "Mikael" mikael.rcv@gmail.com escribió:
Hi Alvaro,
You can traverse all Scm structures from C.
You have typecheckers, car, cdr, vector-ref, accessors for all the specialized vector types and so on.
In the current Gambit version, from all I know, using these works perfectly.
As soon as Gambit goes SMP, this may be a slightly other story and only the objects specifically allocated with ___STILL may be safe to use, we'll see when we get there. What could be an issue would be that the GC would trig during your C call and change all the other object references to an object and then its physical memory location, and you'd be using the old one in your C code.
Do you have a specific question or problem to solve?
Brgds, Mikael
2013/4/12 Álvaro Castro-Castilla alvaro.castro.castilla@gmail.com
There is one thing that I've been meaning to ask for a long time now.
I see most of the people tend to create arrays in C by malloc/___alloc_rc and then assigning values by iterating over them via a setter function (also defined with c-lambda). Isn't there a way to directly do this with a memcpy operation? Wouldn't that be faster?
I understand that Gambit's heap and C's heap are separate, and you need to copy from one another in order to avoid GC touching any of FFI-created memory. But is it possible to improve this process using some sort of C function/macro from Gambit?
I really can't find any code examples or reference for this.
Thank you very much.
Álvaro
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list