Re: Where do I learn how to program Nim without a GC?

2016-08-26 Thread andrea
@Araq Is there any discussion anywhere of the region memory model? You cannot 
expect people to just guess that it exists...

I am not sure if this is supposed to work right now, but I tried


import system/gc_stack

var rx: Region

withRegion rx:
  discard 0


(compiling with `--gc:stack`) and I get the error


lib/system/osalloc.nim(12, 3) Error: undeclared identifier: 'sysAssert'


I am not sure I should import `system/gc_stack` but without it I cannot find 
the symbols `Region` and `withRegion`)


Re: Where do I learn how to program Nim without a GC?

2016-08-25 Thread Araq
Compile with `--gc:stack`


var rx: Region

withRegion rx:
  ... json code here ...


You're right though that it needs documentation. I don't even know if it's in 
0.14.


Re: Where do I learn how to program Nim without a GC?

2016-08-25 Thread jyelon
Yeah, but he needs information on how to cause an normally garbage-collected 
library (for example, the JSON library) to allocate out of a memory region, 
without changing the code for the library. I think the real answer is: I don't 
think memory regions are implemented yet, I don't think anyone's really ironed 
out the details.


Re: Where do I learn how to program Nim without a GC?

2016-08-25 Thread flyx
> I mean somehow I have to tell Nim when to free memory right?

Yeah sure, you just use these: 
[alloc](http://forum.nim-lang.org///nim-lang.org/docs/system.html#alloc,Natural),
 
[dealloc](http://forum.nim-lang.org///nim-lang.org/docs/system.html#dealloc,pointer),
 
[allocShared](http://forum.nim-lang.org///nim-lang.org/docs/system.html#allocShared,Natural),
 
[deallocShared](http://forum.nim-lang.org///nim-lang.org/docs/system.html#deallocShared,pointer).
 You can cast the `pointer` from and to 
[ptr](http://forum.nim-lang.org///nim-lang.org/docs/system.html#ptr) types and 
then you have your manually managed heap memory.

(This is a general answer to how to use non-GC'd memory and has nothing to do 
with memory regions)


Re: Where do I learn how to program Nim without a GC?

2016-08-25 Thread Maxxi
Araq, I dont understand. I'm just now looking into Nimlang. How would I have to 
change the programming style to program with memory regions in Nim? It can't 
just be a flag to the compiler, I mean somehow I have to tell Nim when to free 
memory right?


Re: Where do I learn how to program Nim without a GC?

2016-08-24 Thread Krux02
Is there any documentation on how this should work? How would it be possible to 
define a memory region and then later destroy it? And will there be a mechanism 
to test weather a memory region as still some active references in it?


Re: Where do I learn how to program Nim without a GC?

2016-08-24 Thread Araq
The no GC future is `--gc:stack` which replaces the GC with memory regions. So 
any library that uses the GC really uses a memory region. The entire situation 
is ok. Note that the GC is always thread local anyway, so you can also just run 
realtime threads with other threads that use the stdlib and thus the GC.