Arc Forumnew | comments | leaders | submitlogin
1 point by eds 6099 days ago | link | parent

Also, I think I need to use wait() to wait for a child process to terminate, but I am somewhat at a loss as to how to accomplish this, since the manual says it takes an int pointer... Again, any help would be appreciate.


2 points by stefano 6098 days ago | link

Try:

  (cdef _wait "wait" cint (cptr))

  (def wait (i)
    (let pi (cmalloc 4)
      (cpset pi cint i)
      (_wait pi)))
This creates a pointer, assign it a value and returns the value returned by _wait.

-----

1 point by eds 6093 days ago | link

Also, in your malloc() example, don't you have to explicitly free the memory afterwards? MzScheme's GC doesn't deal with memory explicitly allocated from C, does it? (I know the example itself uses only a tiny amount of memory, but still...)

-----

1 point by sacado 6093 days ago | link

Yes and no. I think mzscheme's GC can handle it without explicitly calling free at the right time, but you have to register a "finalizer" function to do so. That function will be called when the GC collects the object.

It does not know the size of malloced objects however, so be careful (no pb there, but if you allocate something very big, mzscheme will only see a new reference and will not necessarily call GC when you will actually lack memory).

-----

3 points by stefano 6093 days ago | link

If you alloc memory with cmalloc mzscheme will automatically delete it for you. Try

  (def infinite ()
    (cmalloc 4)
    (infinite))

  (infinite)
You shouldn't run out of memory. If you do, then I'm wrong.

-----

1 point by eds 6096 days ago | link

Just wondering: is there a way to malloc(sizeof(int)) from inside Arc instead of hard coding the size of an int?

-----

2 points by stefano 6096 days ago | link

You can make a C function like this:

  int size_of_int ()
  {
    return sizeof(int);
  }
and import it. I've followed this route while writing gtk.arc, but probably there's a better way to do it.

-----