I've taken std.mmfile, and been playing with it.
I won't lie, mostly I've just been messing with it.
The idea was originally to fix opDollar for mmfile (which I can push if
it will be accepted.)
I turned it into a template for funsies.
And a struct. For funsies.
And it Works! mostly.
But only if you don't compile with -O.
-release works, -inline works, -noboundscheck works.
heres an example:
---
import std.conv, std.stdio;
void main()
{
auto mm = mmFile!string("mmTest.d");
string mt = mm[0..50];
string ms = mt[0..50];
string ss = mm.data;
writeln(mm[0..$]);//prints the entire file.
writeln(ms);//prints the first 50 characters.
writeln(mm.data.ptr);//data is the internal string.
writeln(ms.ptr);//all of these should be equal.
writeln(mt.ptr);//But this one and the one above are not.
writeln(ss.ptr);//also nothing gets printed with -O, it segfaults.
return;
}
--
Here is an example output with rdmd mmTest.d:
//the above file[0..$]
//the about file[0..50]
7F47535F5000
7F47535F5000
7F47535F5000
7F47535F5000
Here is outut with rdmd -O mmTest.d:
�
�
7FEA61B77000
406470
406470
7FEA61B77000
What's up with that?

I've taken std.mmfile, and been playing with it.
I won't lie, mostly I've just been messing with it.
The idea was originally to fix opDollar for mmfile (which I can push if
it will be accepted.)
I turned it into a template for funsies.
And a struct. For funsies.
And it Works! mostly.
But only if you don't compile with -O.
-release works, -inline works, -noboundscheck works.
heres an example:
---
import std.conv, std.stdio;
void main()
{
auto mm = mmFile!string("mmTest.d");
string mt = mm[0..50];
string ms = mt[0..50];
string ss = mm.data;
writeln(mm[0..$]);//prints the entire file.
writeln(ms);//prints the first 50 characters.
writeln(mm.data.ptr);//data is the internal string.
writeln(ms.ptr);//all of these should be equal.
writeln(mt.ptr);//But this one and the one above are not.
writeln(ss.ptr);//also nothing gets printed with -O, it segfaults.
return;
}
--
Here is an example output with rdmd mmTest.d:
//the above file[0..$]
//the about file[0..50]
7F47535F5000
7F47535F5000
7F47535F5000
7F47535F5000
Here is outut with rdmd -O mmTest.d:
�
�
7FEA61B77000
406470
406470
7FEA61B77000
What's up with that?

Found it! I was destroy(class) manually allocated class.
That was my fault. Completely. I knew I would be embarrassed if I
posted this. =P
I am now in love with cgdb.
Go get it. It's beautiful.

I've taken std.mmfile, and been playing with it.
I won't lie, mostly I've just been messing with it.
The idea was originally to fix opDollar for mmfile (which I can push if
it will be accepted.)
I turned it into a template for funsies.
And a struct. For funsies.
And it Works! mostly.
But only if you don't compile with -O.
-release works, -inline works, -noboundscheck works.
heres an example:
---
import std.conv, std.stdio;
void main()
{
auto mm = mmFile!string("mmTest.d");
string mt = mm[0..50];
string ms = mt[0..50];
string ss = mm.data;
writeln(mm[0..$]);//prints the entire file.
writeln(ms);//prints the first 50 characters.
writeln(mm.data.ptr);//data is the internal string.
writeln(ms.ptr);//all of these should be equal.
writeln(mt.ptr);//But this one and the one above are not.
writeln(ss.ptr);//also nothing gets printed with -O, it segfaults.
return;
}
--
Here is an example output with rdmd mmTest.d:
//the above file[0..$]
//the about file[0..50]
7F47535F5000
7F47535F5000
7F47535F5000
7F47535F5000
Here is outut with rdmd -O mmTest.d:
�
�
7FEA61B77000
406470
406470
7FEA61B77000
What's up with that?

Found it! I was destroy(class) manually allocated class.
That was my fault. Completely. I knew I would be embarrassed if I posted
this. =P
I am now in love with cgdb.
Go get it. It's beautiful.

Well, mostly. It still has different output on -O, but no longer crashes.

I've taken std.mmfile, and been playing with it.
I won't lie, mostly I've just been messing with it.
The idea was originally to fix opDollar for mmfile (which I can push if
it will be accepted.)
I turned it into a template for funsies.
And a struct. For funsies.
And it Works! mostly.
But only if you don't compile with -O.
-release works, -inline works, -noboundscheck works.
heres an example:
---
import std.conv, std.stdio;
void main()
{
auto mm = mmFile!string("mmTest.d");
string mt = mm[0..50];
string ms = mt[0..50];
string ss = mm.data;
writeln(mm[0..$]);//prints the entire file.
writeln(ms);//prints the first 50 characters.
writeln(mm.data.ptr);//data is the internal string.
writeln(ms.ptr);//all of these should be equal.
writeln(mt.ptr);//But this one and the one above are not.
writeln(ss.ptr);//also nothing gets printed with -O, it segfaults.
return;
}
--
Here is an example output with rdmd mmTest.d:
//the above file[0..$]
//the about file[0..50]
7F47535F5000
7F47535F5000
7F47535F5000
7F47535F5000
Here is outut with rdmd -O mmTest.d:
�
�
7FEA61B77000
406470
406470
7FEA61B77000
What's up with that?

Found it! I was destroy(class) manually allocated class.
That was my fault. Completely. I knew I would be embarrassed if I posted
this. =P
I am now in love with cgdb.
Go get it. It's beautiful.

And It turns out that I f'd up my opSlice as well.
And it seems to be working perfectly now.
Thanks for all the help! I couldn't have done it without you guys!
(that is a light-hearted joke, please take it as such.)