Bug 16564 – KRRegion.empty sometimes returns Ternary.no
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-09-29T09:20:58Z
Last change time
2017-12-18T22:56:58Z
Assigned to
alex.jercaianu
Creator
Temtaime
Comments
Comment #0 by temtaime — 2016-09-29T09:20:58Z
I just tried it as video memory allocator for my engine and empty sometimes don't work: try to allocate and then deallocate in a random order.
For example
void main()
{
ubyte[256 * 1024] buf;
auto a = KRRegion!()(buf);
while(true)
{
void[][] bufs;
foreach(_; 0..10_000)
{
bufs ~= a.allocate(uniform(1, buf.length));
}
foreach(b; bufs.randomCover)
{
a.deallocate(b);
}
if(a.empty == Ternary.no) break;
}
writeln(`all the elements are freed but allocator is not empty !`);
}
Comment #1 by github-bugzilla — 2017-01-19T13:50:31Z
Increasing buffer size from 256 kb to 1 mb causes a crash or returns not empty again
import
std.stdio,
std.random,
std.typecons,
std.algorithm,
std.experimental.allocator.building_blocks;
void main()
{
ubyte[1024 * 1024] buf;
auto a = KRRegion!()(buf);
while(true)
{
void[][] bufs;
foreach(_; 0..10_000)
{
bufs ~= a.allocate(uniform(1, buf.length));
}
foreach(b; bufs.randomCover)
{
a.deallocate(b);
}
if(a.empty == Ternary.no) break;
}
writeln(`all the elements are freed but allocator is not empty !`);
}
Comment #5 by dlang-bugzilla — 2017-07-06T21:40:23Z
(In reply to Temtaime from comment #4)
> ubyte[1024 * 1024] buf;
Are you sure that's not just because you have a 1MB static array on the stack?
This program, by itself, crashes on Windows (because of stack overflow):
void main()
{
ubyte[1024 * 1024] buf;
}
Comment #6 by andrei — 2017-07-07T21:49:58Z
@Temtaime should this stay open?
Comment #7 by temtaime — 2017-07-13T15:17:57Z
Oh, sorry, my mistake
import
std.stdio,
std.range,
std.random,
std.typecons,
std.algorithm,
std.experimental.allocator.building_blocks,
core.memory;
void main()
{
ubyte[128 * 1024] b;
auto alloc = KRRegion!()(b);
//alloc.switchToFreeList;
auto k = alloc.allocate(128);
assert(alloc.deallocate(k));
assert(alloc.empty == Ternary.yes);
}
I don't know why but this simplest example asserts.
More complex tests are passed. Also it passes if the switch in uncommented
Comment #8 by github-bugzilla — 2017-11-19T02:40:56Z