How to best access a potentially const variable in a func that is to big for default stack?

2021-03-26 Thread shirleyquirk
i assume your `type B` is actually `array[64,array[64,array[64,array[64,int32` as 64*64*6*64 actually compiles and runs just fine (on linux anyway, with 8MB stack) FIrst some bad answers: to increase the stack you can try `{.passL: "-z stack-size=67109864".}` where the number is sizeof(B)+

How to best access a potentially const variable in a func that is to big for default stack?

2021-03-26 Thread leorize
AFAIK `const` arrays are inlined into the executable and won't take up any stack space (unless you perform a copy to stack, which you're not doing in this example).

How to best access a potentially const variable in a func that is to big for default stack?

2021-03-26 Thread tsojtsoj
I have a program like this: type B = array[64, array[64, array[6, array[64, int32 const defaultB: B = block: var r: B ... r func hi(i: int32): int32 = defaultB[i][i][i div 10][i] * i echo hi(9) Run The problem

How to use global immutable variables in Threads?

2021-03-26 Thread shirleyquirk
Yes, this method is 'mentioned in the docs<[https://nim-lang.org/docs/channels.html#example-passing-channels-safely>'](https://nim-lang.org/docs/channels.html#example-passing-channels-safely>')_

Error: unknown substition variable: attype

2021-03-26 Thread shirleyquirk
Is this related to maybe?

Error: unknown substition variable: attype

2021-03-26 Thread user71383
I would love to use choosenim but it is not running anymore without IPv6 :( oserr.nim(94)raiseOSError Error: unhandled exception: Address family not supported by protocol [OSError] Run I'm not allowed to use IPv6 :(

How to use global immutable variables in Threads?

2021-03-26 Thread alexeypetrushin
I just realised there's also the `ptr`. Could it be used? import mimetypes, threadpool, strformat var mime: ptr MimeDB mime = create(MimeDB) mime[] = new_mimetypes() proc parse_format(): string {.gcsafe.} = mime[].get_ext("text/html", "unknown")

Error: unknown substition variable: attype

2021-03-26 Thread user71383
Thank you very much. It is exactly as you write. I overlooked it twice. shame on me :(

How to use global immutable variables in Threads?

2021-03-26 Thread alexeypetrushin
> there's lots of way to share things across threads I was wondering, would it be currently possible in Nim to do something like a database query? Make one thread responsible for storing large data object. And while not sharing the data directly, allow other threads to query the data (submit a

How to use global immutable variables in Threads?

2021-03-26 Thread boia01
@alexeypetrushin Sorry I missed reading your postscriptum: > P.S. There's also a way to use {.threadvar.} and keep separate copy for each > thread. But it defeats the whole point of having multi threaded server that > could optimise memory by sharing some common data between threads. Yes, you'r

Error: unknown substition variable: attype

2021-03-26 Thread shirleyquirk
that line in the nimdoc.cfg changed in v1.4.2. pacman doesn't overwrite config files when upgrading: [(arch wiki)](https://wiki.archlinux.org/index.php/Pacman/Pacnew_and_Pacsave) I expect you have a .pacnew file with the upgrade that you need to move over. I recommend pacmatic for upgrading, it

How to use global immutable variables in Threads?

2021-03-26 Thread alexeypetrushin
The `gcsafe` block is different from `gcsafe` proc. The `gcsafe` procs are proper way, verified by compiler. While the `gcsafe` block forces compiler to compile unsafe code anyway.

How to use global immutable variables in Threads?

2021-03-26 Thread boia01
The general rule is to avoid sharing refs across threads. Nim's main GC algorithms (ARC, ORC) do not provide the guarantee that reference-counting is thread-safe. And more specifically, even protecting access to the root of an object graph through a lock is generally insufficient, because even

How to use global immutable variables in Threads?

2021-03-26 Thread r3c
I've never saw crash in a gcsafe marked proc, but if someone knows better solution please post it.

How to use global immutable variables in Threads?

2021-03-26 Thread alexeypetrushin
A second though **about forcefully using `gsafe`** block. Actually, it should be safe to use it in this case. There going to be no race conditions as the data is immutable. And, this memory can't be erased, as the variable would be never garbage collected, and it's in the main thread that's nev

How to use global immutable variables in Threads?

2021-03-26 Thread alexeypetrushin
Passing as a parameter won't work, it's a simplified example. The actual usage is in multi-threaded web server, where some helper methods detect MIME type. Using `gcsafe` block forces it to compile, and it works. But... not sure how safe to use it, maybe it would crash randomly or stop working w

Converter string to raw

2021-03-26 Thread modolo
Thanks! This is exactly what I was looking for! I started programming a little while ago with nim! Regards, Marcelo Módolo

How to use global immutable variables in Threads?

2021-03-26 Thread Symb0lica
I suspect you will have to pass **mime** as a parameter (unless someone knows of a better way).

How to use global immutable variables in Threads?

2021-03-26 Thread r3c
import mimetypes, threadpool proc parse_format(mime: any): string = mime.get_ext("text/html", "unknown") var cresp = spawn parse_format(new_mimetypes()) echo ^cresp Run

How to use global immutable variables in Threads?

2021-03-26 Thread alexeypetrushin
The example below would fail complaining that it's not `gsafe`, and `let` can't be changed into `const`. How it should be handled, is there a directive to tell Nim compiler to put `let` into globally shared memory? import mimetypes, threadpool let mime = new_mimetypes()

2nd Nim online meetup

2021-03-26 Thread miran
> The 2nd Nim online meet will take place this Friday (March 26th) at 4pm UTC Just a reminder that this will happen today when this post is 7 hours old.

Error: unknown substition variable: attype

2021-03-26 Thread user71383
When I call 'nim doc foo.nim' with version 1.4.4 the following error shows up: > Error: unknown substition variable: attype A quick search revealed the problem in '/etc/nim/nimdoc.cfg' ... # Chunk of HTML emitted for each entry in the HTML table of contents. # See doc.i