Debugging with GDB?

2024-03-15 Thread zevv
You might want to ask gdb. Try the `backtrace` command.

Have I written a silly program or is there a "controlled" memory leak?

2024-03-08 Thread zevv
valgrind is your friend.

Best REGEX library for targeting both JS and C

2024-03-07 Thread zevv
NPeg is pure nim, it does not rely on any backend whatsoever; it should run just fine with any target. If not, file a bug and we fix it.

Best REGEX library for targeting both JS and C

2024-03-06 Thread zevv
Not quite regexp, but PEG instead. Compatible with any backend, run-time and compile time: <https://github.com/zevv/npeg>

Have I written a silly program or is there a "controlled" memory leak?

2024-03-06 Thread zevv
Missing db.close() in the "Rows are already written to DB" return

Can ref variables reference non-ref variables?

2024-02-26 Thread zevv
> Can ref variables reference non-ref data? Depends on what you mean with 'reference', you're free to take the address to any data, wherever it lives and use that. But this will not mean Nim will manage the memory and lifetime of the object for you. > If possible, how do I get safe references t

create ungraceful exit program

2024-02-16 Thread zevv
There is no simple way to do this: on program termination - graceful or not - the operating system will clean up system resources that the program was using. For example, this means that any TCP connections that were established will be properly terminated by the operating system, informing the

SIGSEGV: Illegal storage access. (Attempt to read from nil?) in coroutines

2023-12-22 Thread zevv
Of course there is still CPS, where the overhead of a continuation is only tens of bytes, no stacks need to be allocated and no support from the OS is needed to switch contexts. CPS has been used to build coroutines, actors, fibers and more, and easily scales to thousands or millions of concurr

SIGSEGV: Illegal storage access. (Attempt to read from nil?) in coroutines

2023-12-22 Thread zevv
The part I was referring to in particular is the `wait()` function that causes in a nil deref when called from a non-fiber context.

SIGSEGV: Illegal storage access. (Attempt to read from nil?) in coroutines

2023-12-16 Thread zevv
Don't use `std/coro`, it's broken.

Move ref variable ro thread

2023-11-14 Thread zevv
Not quite safe yet I'm afraid. Run with tsan or helgrind for more details: nim r --passC:-fsanitize=thread --passL:-fsanitize=thread t.nim Run WARNING: ThreadSanitizer: data race (pid=1279003) Read of size 8 at 0x7f74a5300050 by thread T1: #0

unique refs > `isolate`

2023-05-09 Thread zevv
Thanks Araq, nice to see this; I think this is part of the infrastructure we need to make these kind of operations safe. I see the implementation verifies the RC of the referenced object itself is zero; do you have any opinions on doing deep/recursive inspection of a graph?

Atomic ARC

2023-05-07 Thread zevv
AMD Ryzen 7 3700X arc: 166803 lines; 5.829s; 490.867MiB peakmem atomicArc: 166803 lines; 5.878s; 490.758MiB peakmem;

locks on dynamically allocated memory

2023-05-06 Thread zevv
This is one way to do it. There are probably nicer ways, but this is pretty explicit to show what is happening. import std/locks type Thing = object val: int lock: Lock ThingInfo = object thingPtrs: ptr UncheckedArray[Thing]

locks on dynamically allocated memory

2023-05-06 Thread zevv
No, the guard is not what you are looking for; you will need to put a regular mutex in your object and manually lock/unlock it when you are accessing your data. The .guard informs the Nim compiler about your intentions with regards to locking, it can help you protect your data by warning you th

locks on dynamically allocated memory

2023-05-06 Thread zevv
If you make a seq of objects, you should be able to access the individual elements of the seq by their raw pointer address from your threads, and put a lock in these individual elements for fine grained locking of their contents. >From your different threads perspectives, ignore the fact that th

Usability of ARC/ORC in multi threaded code.

2023-05-03 Thread zevv
You asked for an example, which I provided - apologies if that does not answer your question. I think I provided a valid example though, which is about safety. The only way to move data to another thread is by passing it through `unsafeIsolate()`. As a programmer I make a lot of stupid mistakes

Usability of ARC/ORC in multi threaded code.

2023-05-03 Thread zevv
The problem is not in my actors or in any other code I wrote, but has to do with whatever the user might want to send through a channel. My example would be just the same as your example: just two threads and a single channel. No different from sending messages to actors through mailboxes. At t

Usability of ARC/ORC in multi threaded code.

2023-05-03 Thread zevv
@araq: " _The real question is how hard it is for client code to avoid triggering (non atomic) ARC problems when using your actors runtime_ " It is **inevitable** that client code will trigger ARC problems when using my actors runtime. And I do not know how to solve this. _this_ is the point I a

Usability of ARC/ORC in multi threaded code.

2023-05-03 Thread zevv
@araq: Your example is demonstrating moving a _constant_ tree around has never been easier. It is showing the happy path because `isolate()` is able to take your const JSON tree and isolate it; when trying to pass anything else, `isolate()` is no longer able to do the job and will tell you `exp

Is ORC considered production-ready? What is the consensus on its use?

2023-05-03 Thread zevv
@termer: I was about to write a lengthy response, but decided to put it in a new thread instead:

Usability of ARC/ORC in multi threaded code.

2023-05-03 Thread zevv
The Actors project is more or less complete, and is in a works-for-me state, but I must admit that I have not actually _used_ it for very much after I got it to work; For those interested, take a peek at <https://github.com/zevv/actors> A short summary of my conclusions, not complete and

Debugging Memory Usage in Nim

2023-03-16 Thread zevv
oing, also fun to watch and compare different GC implementations at work, for example: <https://github.com/zevv/memgraph>

Example of simple parser?

2023-03-13 Thread zevv
<https://github.com/zevv/npeg> might fit your needs.

Shared global var in ORC?

2023-03-11 Thread zevv
Yeah, that's an oldie, I ran in exactly the same issue in 2018:

Debugging Memory Usage in Nim

2023-02-27 Thread zevv
When on Linux: compile with `--debugger:native -d:useMalloc`, put in a `quit()` somewhere and run your program on valgrind; when the process exists valgrind will tell you exactly which memory has been allocated where. Example: type Foo = ref object val: int proc flop

question about memory management

2022-12-24 Thread zevv
I think I missed something, what did @Stefan_Salewski do or say to deserve an ad hominem attack like that?

Nim 2: "Memory can be shared effectively between threads without copying in Nim version 2"

2022-11-18 Thread zevv
I am not familiar with the workings of orc, so this might be nonsense: is the problem that the the ref cell `rootIdx`'s are pointing to the wrong threads `roots`? Should I re-root all refs of my tree after moving them?

Nim 2: "Memory can be shared effectively between threads without copying in Nim version 2"

2022-11-17 Thread zevv
Please disregard my previous comment; for some reason nimforum does not allow me to delete or edit :(

Nim 2: "Memory can be shared effectively between threads without copying in Nim version 2"

2022-11-17 Thread zevv
I wrote some simple and naive code to check if a tree is isolated at runtime, see <https://github.com/zevv/nimsafesend>. `isIsolated[]()` recursively traverses the passed (ref) objects and finds out if the passed ref is isolated, and thus safe to move to a different thread. In main

Nim 2: "Memory can be shared effectively between threads without copying in Nim version 2"

2022-11-17 Thread zevv
> So you can use unsafeIsolate to do what we want? No; `unsafeIsolate` will happily do what you ask it, but it will not check or enforce the actual RC count. It creates an `isolated[T]` for you which might or might not be isolated. I do not really see any use cases in which this would be useful

Nim 2: "Memory can be shared effectively between threads without copying in Nim version 2"

2022-11-16 Thread zevv
Globals are not special in any way here, this goes for any other ref variable that you want to share/move over threads. My original problem is about how to move data between threads. One of the ideas behind arc was that "[...] reference counting operations [...] do not use atomic instructions a

Nim 2: "Memory can be shared effectively between threads without copying in Nim version 2"

2022-11-16 Thread zevv
Sure, nim-lang/threading solves this basically by re-implementing part of arc but using atomics for the RCs instead. That solves my particular problem, but this does not integrate seamless with the rest of arc of course. This is one of the cases where arc could shine, if it were to support this

Nim 2: "Memory can be shared effectively between threads without copying in Nim version 2"

2022-11-16 Thread zevv
Here is my minimal example: (This does not actually run in the playground because it needs devel) This example creates two threads, a ref object is created in one thread and sent to the other over a channel. (For now, ignore the fact there is no locking or m

Nim 2: "Memory can be shared effectively between threads without copying in Nim version 2"

2022-11-16 Thread zevv
Is there a way to make sure (by inspection or enforced by the compiler) that the moved ref RC == 1, other then wrapping the ref in an `isolated[]`? When the ref counter of the moved object > 1, both threads will have a reference to the same object, leading to disaster. `isolated[]` is not pract

Nim 2: "Memory can be shared effectively between threads without copying in Nim version 2"

2022-11-15 Thread zevv
Araq's recent post "A cost model for Nim" states that "Memory can be shared effectively between threads without copying in Nim version 2". This is related to a problem I have been struggling with for a long time. Basically, the problem is this: * I have a program with two threads, A and B.

From too many copies to too few

2022-10-16 Thread zevv
"Jesus Christ these things are neither hard nor unique to Nim." Come on Araq, this is no way of answering any kind of question on the forum, especially from someone in your position.

Nim v2: what would you change?

2022-05-01 Thread zevv
Please consider making circular dependent types possible. I have largely abandoned Nim as my primary language because I always run into the same problem when my projects grow larger than a handful of files: I need to put all my types into a single type block in a single file. This simple does n

Comprehensive knowledge on Nim memory management (MM)

2022-02-26 Thread zevv
Take a peek at for more details

Unable to use HashSet for my type

2021-01-06 Thread zevv
I always wondered, why is there no generic Hash in stdlib like: proc hash[T: object | ref object](o: T): Hash = var h: Hash = 0 for k, v in o.fieldPairs: h = h !& v.hash result = !$h Run

AVR Support?

2021-01-04 Thread zevv
This works fine for me for nim-arduino [1], and allows most of the stdlib to be used as well: --cpu:avr --os:any --gc:arc --exceptions:goto -d:noSignalHandler -d:danger -d:useMalloc Run 1\. <https://github.com/zevv/nim-arduino>

Is it possible to generate a list of all transient dependencies and their sources?

2020-12-26 Thread zevv
"I fail to build this due to an unsatisfied dependency error" That is pretty ironic :(

Method/Procedure that returns values of multiple types?

2020-12-06 Thread zevv
`method getVal(l: static[Literal]): auto = when l.kind == lkSym: result = l.symVal when l.kind == lkInt: result = l.intVal when l.kind == lkFlt: result = l.fltVal ` Run

compile-time import

2020-11-24 Thread zevv
`--os:any --gc:arc and -d:useMalloc` is the tested and proven trio that should work on any reasonable ANSI C implementation. If you even lack a decent stdlib you can stub some of the basic functions like `malloc()`, `fopen()` and still get to run on bare silicon.

Someone have an idea on how to implement a `[][]=` function?

2020-11-04 Thread zevv
Make it a two-step process: import tables type FormTableSeq[T] = seq[T] FormTableRef[T] = ref object table: Table[string, FormTableSeq[T]] proc `[]`*[T](f: FormTableRef[T], key: string): var seq[T] = f.table[key] proc `[

does using `result` guarantee NRVO?

2020-08-22 Thread zevv
Does this still hold with ARC?

Improving Nim for Beginners video series's AUDIO

2020-08-13 Thread zevv
Hi Kiloneie, maybe this is of any help: Some time ago we had a visitor on the #nim IRC channel who came to us to vent about the sound quality of some of the NimConf videos. The good thing is that he did not only complain, but also came with some good advice, and offered to be contacted for any

Sandboxing untrusted Nimscript code

2020-08-06 Thread zevv
Nim playground works by spawing the compiler in a docker container. Might be overkill but it seems pretty effective.

How to instantiate custom `TableRef` without repeating individual types?

2020-08-06 Thread zevv
https://play.nim-lang.org/#ix=2tqy

How to instantiate custom `TableRef` without repeating individual types?

2020-08-06 Thread zevv
var myTable: ATableRef new myTable

What are Nim programmers called?

2020-07-16 Thread zevv
Levian: this was my FOSDEM shirt this year: [http://zevv.nl/div/.old/ni2.jpg](http://zevv.nl/div/.old/ni2.jpg)