C++ Logo

std-proposals

Advanced search

Re: Coroutine local destructor

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Fri, 22 May 2020 19:52:34 +0200
Arthur O'Dwyer:
> Could you post a complete compilable example, something with a clear metric for "works as intended"? I can't follow these one-line snippets at all.

This is what I try archive:
https://gcc.godbolt.org/z/hhiBYZ

Idea is have stackfull corutine with local memory allocation. Idea is
that you can have multiple corutines start in one function and each
have its own buffer.

This code do not compile because standard forbid code like:
```

        void* operator new(std::size_t s, LocalStack& ls) noexcept
        {
            //auto p = ::operator new(s);
            auto p = ls.curr;
            ls.curr += s;

            std::printf("new %p\n", p);
            return p;
        }
        void operator delete(void* p, LocalStack& ls)
        {
            std::printf("delete %p\n", p);

            ls.curr = static_cast<char*>(p);
            // ::operator delete(p);
        }

```

There is now easy way to have this `LocalStack&` for `delete`.
Right now only way I see is add special code to `task<>` destructor
and pass information other way to correctly release memory.

Received on 2020-05-22 12:55:49