Keeping data from memory mapped files
Why do I need to copy data out of memory mapped files to avoid seg faults. This defeats the purpose of memory mapped files. Shouldn't the GC be able to manage it if I keep a pointer into it. I am closing them because the OS has a limit in how many it can open, either way the memory is still there isn't it ?
Re: Function Pointer
On Wednesday, 30 August 2023 at 21:12:57 UTC, Paul Backus wrote: On Wednesday, 30 August 2023 at 17:48:19 UTC, Vino wrote: Hi All, Request your help on hot to create a pointer for a function whose function type is Result. ``` ReturnType!(typeof(&test)).stringof; // Result From Vino ``` To get a function pointer type from a function type, you can add `*` on the end: void func(int) {} alias FuncType = typeof(func); pragma(msg, FuncType); // void(int) alias FuncPtrType = FuncType*; pragma(msg, FuncPtrType); // void function(int) static assert(is(FuncPtrType == typeof(&func))); Thank you very much
Re: pointer to std.algorithm.iteration : splitter
On Thursday, 31 August 2023 at 10:46:53 UTC, Dukc wrote: On Thursday, 31 August 2023 at 05:16:02 UTC, Vino wrote: [...] I'm assuming you want to instantiate `splitter` and take the address of the resulting function, so that `splitter_ptr` will be a function pointer or a delegate. [...] This is what I expected, thank you very much
Re: I don't understand betterC
On Thursday, 31 August 2023 at 18:42:57 UTC, Richard (Rikki) Andrew Cattermole wrote: ```d extern(C) int main() { import core.stdc.stdio; string hello = "hello"; printf(hello.ptr); return 0; } ``` 1) You forgot to import ``core.stdc.stdio`` 2) String literal is of type string (which is an alias to ``immutable(char)[]``). 3) A slice is a pointer + length, and C doesn't understand slices, so you must explicitly pass in the pointer from the slice (the compiler would do this for you if you had the literal in the arguments list instead of the variable). ```d import core.stdc.stdio; ``` This generates ``` Error: undefined identifier `size_t` ```.
Re: I don't understand betterC
```d extern(C) int main() { import core.stdc.stdio; string hello = "hello"; printf(hello.ptr); return 0; } ``` 1) You forgot to import ``core.stdc.stdio`` 2) String literal is of type string (which is an alias to ``immutable(char)[]``). 3) A slice is a pointer + length, and C doesn't understand slices, so you must explicitly pass in the pointer from the slice (the compiler would do this for you if you had the literal in the arguments list instead of the variable).
I don't understand betterC
I decided to try out betterC with the most trivial example I could think of, but why doesn't this work? ```d extern(C) int main() { char[] hello = "hello"; printf(hello); return 0; } ```
Re: pointer to std.algorithm.iteration : splitter
On Thursday, 31 August 2023 at 05:16:02 UTC, Vino wrote: Hi All, Request your help on the below error Program ``` void main() { import std.stdio:writeln; import std.algorithm.iteration : splitter; auto splitter_ptr = &splitter!((a, b) => a.splitter(b).array); string str = "TEST1;TEST2;TEST3"; auto words = splitter_ptr(str, ';'); foreach (word; words) { writeln(word); } } ``` ``` Error: template instance `splitter!((a, b) => a.splitter(b).array)` does not match any template declaration ``` From, Vino I'm assuming you want to instantiate `splitter` and take the address of the resulting function, so that `splitter_ptr` will be a function pointer or a delegate. You are getting the compile time arguments to `splitter` utterly wrong. It should take: - A function that checks equality between an element and a separator. - a `keepSeparators` flag. - type of the range you're passing in, `string` in this case. - type of the separator, `char` or `dchar` in this case. You can find this all in [the docs](https://dlang.org/phobos/std_algorithm_iteration.html#.splitter). I think you accidentally passed what you wanted to do with `splitter` as a compile-time parameter to it. I don't think it's very practical to try instantiating a complex templated function like `splitter` without calling it. It's just not designed for that. I'd rather define a function that wraps a call to it, like (not tested, may have errors): ```D auto splitter_ptr = (string str, dchar sep) => str.splitter(sep).array; ``` Maybe that's what you tried in the first place. You don't need `&` here, because a lambda (which we use here) is already a function pointer (or a delegate).
Re: pointer to std.algorithm.iteration : splitter
On Thursday, 31 August 2023 at 05:16:02 UTC, Vino wrote: Hi All, Request your help on the below error Program ``` void main() { import std.stdio:writeln; import std.algorithm.iteration : splitter; auto splitter_ptr = &splitter!((a, b) => a.splitter(b).array); string str = "TEST1;TEST2;TEST3"; auto words = splitter_ptr(str, ';'); foreach (word; words) { writeln(word); } } ``` ``` Error: template instance `splitter!((a, b) => a.splitter(b).array)` does not match any template declaration ``` From, Vino Why are you trying to take pointers of lots of different things? You should pretty much never need pointers in normal D code.
Re: Ideas to reduce error message size?
On Wednesday, 30 August 2023 at 09:24:21 UTC, Paolo Invernizzi wrote: src/api3.d(49):called from here: `checkSql(Schema("public", src/dget/db.d(276): Error: template instance `api3.forgeSqlCheckerForSchema!(Schema("public", **BAZILLIONS of lines**> error instantiating ``` The compiler could limit the call expression to a few lines unless the verbose flag is passed. A similar problem exists when calling a function literal which errors, the whole body is printed which can be long.