Re: I can has @nogc and throw Exceptions?

2018-07-19 Thread timotheecour via Digitalmars-d-learn
On Friday, 13 February 2015 at 19:03:10 UTC, Jonathan Marler wrote: This question comes from wanting to be able to throw an exception in code that is @nogc. https://dlang.org/changelog/2.079.0.html#dip1008 ```d void main() @nogc { throw new Exception("I'm @nogc now"); } ```

Re: I can has @nogc and throw Exceptions?

2016-07-14 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 22:42:36 UTC, Adam Sansier wrote: On Wednesday, 13 July 2016 at 21:27:16 UTC, Lodovico Giaretta wrote: At the end, all memory comes from one of these: GC heap, malloc, mmap, sbrk. All other allocators build on top of these (or on top of user supplied buffers,

Re: I can has @nogc and throw Exceptions?

2016-07-13 Thread Adam Sansier via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 21:27:16 UTC, Lodovico Giaretta wrote: On Wednesday, 13 July 2016 at 21:12:29 UTC, Adam Sansier wrote: [...] Ok, I like! [...] I like too! But I'll have to assume you are right since I have no proof. [...] Well, one could do this with malloc because one

Re: I can has @nogc and throw Exceptions?

2016-07-13 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 21:12:29 UTC, Adam Sansier wrote: The advantages over a simple malloc are: 1) You can change between GC allocation, malloc, mmap and other allocators by changing a single line, instead of changing every throw; Ok, I like! 2) you can use very fast allocators,

Re: I can has @nogc and throw Exceptions?

2016-07-13 Thread Adam Sansier via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 20:57:49 UTC, Lodovico Giaretta wrote: On Wednesday, 13 July 2016 at 20:44:52 UTC, Adam Sansier wrote: On Wednesday, 13 July 2016 at 16:28:23 UTC, Lodovico Giaretta wrote: It's actually quite easy. Here's the code (untested):

Re: I can has @nogc and throw Exceptions?

2016-07-13 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 20:44:52 UTC, Adam Sansier wrote: On Wednesday, 13 July 2016 at 16:28:23 UTC, Lodovico Giaretta wrote: It's actually quite easy. Here's the code (untested): import

Re: I can has @nogc and throw Exceptions?

2016-07-13 Thread Adam Sansier via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 16:28:23 UTC, Lodovico Giaretta wrote: On Wednesday, 13 July 2016 at 16:13:21 UTC, Adam Sansier wrote: On Wednesday, 13 July 2016 at 11:39:11 UTC, Lodovico Giaretta wrote: On Wednesday, 13 July 2016 at 00:57:38 UTC, Adam Sansier wrote: [...] You shall use a

Re: I can has @nogc and throw Exceptions?

2016-07-13 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 16:13:21 UTC, Adam Sansier wrote: On Wednesday, 13 July 2016 at 11:39:11 UTC, Lodovico Giaretta wrote: On Wednesday, 13 July 2016 at 00:57:38 UTC, Adam Sansier wrote: [...] You shall use a static per-thread Region allocator[1] backed by Mallocator[2]. Then you

Re: I can has @nogc and throw Exceptions?

2016-07-13 Thread Eugene Wissner via Digitalmars-d-learn
I'm writing currently a library, that is 100% @nogc but not nothrow, and I slowly begin to believe that I should publish it already, though it isn't ready yet. At least as example. std.experimental.allocator doesn't work nicely with @nogc. for example dispose calls destroy, that isn't @nogc. I

Re: I can has @nogc and throw Exceptions?

2016-07-13 Thread Adam Sansier via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 11:39:11 UTC, Lodovico Giaretta wrote: On Wednesday, 13 July 2016 at 00:57:38 UTC, Adam Sansier wrote: [...] You shall use a static per-thread Region allocator[1] backed by Mallocator[2]. Then you just make[3] exceptions inside it and throw them. So you can

Re: I can has @nogc and throw Exceptions?

2016-07-13 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 00:57:38 UTC, Adam Sansier wrote: How about simply setting aside a 100kb of memory as a pool for exceptions. Seems like a lot but still under 640kb, hell, even 1MB would still be tiny. After all, it's not like exceptions are common or happen in complex ways.

Re: I can has @nogc and throw Exceptions?

2016-07-12 Thread Adam Sansier via Digitalmars-d-learn
On Friday, 13 February 2015 at 21:08:58 UTC, Marc Schütz wrote: On Friday, 13 February 2015 at 19:09:43 UTC, Tobias Pankrath wrote: 1. Throw preallocated exceptions is the way to go ... and because noone has yet shown an explicit example: void myThrowingNogcFunc() @nogc { static

Re: I can has @nogc and throw Exceptions?

2015-02-13 Thread Tobias Pankrath via Digitalmars-d-learn
On Friday, 13 February 2015 at 19:03:10 UTC, Jonathan Marler wrote: This question comes from wanting to be able to throw an exception in code that is @nogc. I don't know if it's possible but I'd like to be able to throw an exception without allocating memory for the garbage collector? You

Re: I can has @nogc and throw Exceptions?

2015-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/13/15 2:03 PM, Jonathan Marler wrote: This question comes from wanting to be able to throw an exception in code that is @nogc. I don't know if it's possible but I'd like to be able to throw an exception without allocating memory for the garbage collector? You can do it in C++ so I think

I can has @nogc and throw Exceptions?

2015-02-13 Thread Jonathan Marler via Digitalmars-d-learn
This question comes from wanting to be able to throw an exception in code that is @nogc. I don't know if it's possible but I'd like to be able to throw an exception without allocating memory for the garbage collector? You can do it in C++ so I think you should be able to in D. One idea I

Re: I can has @nogc and throw Exceptions?

2015-02-13 Thread Jonathan Marler via Digitalmars-d-learn
On Friday, 13 February 2015 at 19:13:02 UTC, Steven Schveighoffer wrote: You need to actually allocate the memory on the heap. Your data lives on the stack frame of main, which goes away as soon as main exits, and your exception is caught outside main. -Steve Yes I am aware of this. That

Re: I can has @nogc and throw Exceptions?

2015-02-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 13 February 2015 at 19:03:10 UTC, Jonathan Marler wrote: T construct(T,A...)(void* buffer, A args) { return (cast(T)buffer).__ctor(args); } This is wrong, you need to initialize the memory first to the proper values for the class, gotten via typeid(T).init. std.conv.emplace does

Re: I can has @nogc and throw Exceptions?

2015-02-13 Thread Jonathan Marler via Digitalmars-d-learn
On Friday, 13 February 2015 at 19:10:00 UTC, Adam D. Ruppe wrote: On Friday, 13 February 2015 at 19:03:10 UTC, Jonathan Marler wrote: T construct(T,A...)(void* buffer, A args) { return (cast(T)buffer).__ctor(args); } This is wrong, you need to initialize the memory first to the proper

Re: I can has @nogc and throw Exceptions?

2015-02-13 Thread via Digitalmars-d-learn
On Friday, 13 February 2015 at 19:09:43 UTC, Tobias Pankrath wrote: 1. Throw preallocated exceptions is the way to go ... and because noone has yet shown an explicit example: void myThrowingNogcFunc() @nogc { static const exc = new Exception(something went wrong); throw

Re: I can has @nogc and throw Exceptions?

2015-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/13/15 4:08 PM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: On Friday, 13 February 2015 at 19:09:43 UTC, Tobias Pankrath wrote: 1. Throw preallocated exceptions is the way to go and because noone has yet shown an explicit example: void myThrowingNogcFunc() @nogc {