C++ Logo

std-proposals

Advanced search

Re: [std-proposals] : Re: [PXXXXR0] Add a New Keyword ‘undecl’

From: SD SH <Z5515zwy_at_[hidden]>
Date: Mon, 15 Dec 2025 15:08:19 +0000
> But then (if drop or undecl is implemented), the stack would fragment.
The restriction of scope we have talked (on Friday) can avoid this problem. By this way, the addresses of objects on stack is known and fixed.

> (if it is just one, there is no performance gain in freeing before the end of the scope)
Assume `undecl` ends the object in this example:

```
alignas(64) std::byte arr[64];
// do something about using it
// it usually stays in cache when we used it just now
undecl arr; // free the former 'arr'
int arr[8]; // then we can overwrite the storage of former 'arr' and access the latter 'arr' without waiting for memory
// if the former 'arr' isn't ended when using `undecl`, sometimes the processor has to wait for main memory and gets worse performance.
```
The fact is that sometimes it brings better performance.


Received on 2025-12-15 15:08:26