Code:
~Block(void) { if (elements_) //?$
delete[] elements_;
}
I think this actually might've been my code. I think it's something that needs to be trashed, tbh. It was my attempt at preventing a double free/delete but I think delete is 'safe' in the sense that if you pass in a nullptr or something logically equivalent, it just returns harmlessly.
Code:
new(tmp) T(t); //?1
I think this is supposed to create an element in-place using the copy constructor of the specified type. Again, this is my own code. This is actually what we want to use though. Inserting an element is logically equivalent to constructing an element in the container so this is acceptable. We're constructing a new element using a copy of an old one.
Code:
new(tmp) T(std::move(t)); //?1
This is similar to above, just this time we're using the move constructor to construct a new element. This is so data without a more permanent address can be transferred to data that is assignable. I think that's how lvalue and rvalue stuff works. lvalues were assignable while rvalues were objects unwind from the stack before current scope changes clean them up automatically. Like, values that disappear after a calculation, for example. 1 + 2 destructs immediately upon its assignment to something more permanent.
Code:
void mark(void * f) { //?!
if (flag.end() == flag.find(f))
flag[f] = 1;
else {
++flag[f];
std::cout << "what? (con): (" << f << ", " << flag[f] << ")\n";
}
}
Hmm...
You're doing a look-up based on an address. If the address does not exist in the map, the flag is set to 1 (therefore free). Otherwise, if the value is there, increment the value and by doing so, you're making this address as one that points to an object whose destructor needs to be called. It's the implementation of the idea I threw out there towards the end of my post. I think std::map is iterable too.
Code:
void unmark(void * f) { //?!
if (flag.end() != flag.find(f)) // if (address is in map)
if (flag[f] == 1) // if element is 'free', just harmlessly erase (no destructors need to be called)
flag.erase(f);
else {
std::cout << "what? (dec): (" << f << ", " << flag[f] << ")\n";
--flag[f]; // else set this address back to its free state (I really hope a destructor is called sometime near when this one is)
}
else { // this part I don't get... if flag isn't in the map, does writing flag[f] implicitly add it there?
// Oh, it does. Ha! How neat! Anyway, if the address we're looking to unmark isn't in the map,
// we go ahead and yolo add it. Now, as to why we go ahead and it anyway, I guess it's because
// we're drawing attention to an address and it'd be good to track its state in some way.
std::cout << "what? (dec): (" << f << ", " << flag[f] << ")\n";
--flag[f];
}
}