Delete void pointer with 'delete' keyword -- given size. How?

I am stil trying making a C++ version of my C# class for working with Dragon Age: Origin's 2DA tables. Solely for learning's sake. The values are void* as they're type casted. I happen to know the exact size of the values. Can I delete void pointer's value given that size?
No. If you know their type, cast them then delete. Otherwise, there's nothing you can do.
Is this something that actually work?

1
2
3
4
5
6
bool* ptr = ((bool*)iter->values[i].value); // Any 1-byte type would do
for(int j = 0; j < columnSizes[j]; j += 1)
{
	delete ptr;
	ptr++;
}


Edit: put that in wrong if-block, gave me an assertion, is there any other way to do something with a similiar idea?

Edit2: As 1 and 4 are the only lengths I work with, is it safe to cast them to a simple type (char for 1 and int for 4), given those values are either int, bool or float?
Last edited on
Strictly speaking, no, it's not safe. Practically speaking, AFAIK no implementation should give you trouble because of that.
Still, there's something wrong with your design if you're forced to do something like this.
The bools are sometimes padded, sometimes not. It's not my file format. That's what happens when the company making that game wants a generic data format and G2DA I am trying to make a class for is an underformat using that format.

Edit: treating padded-bools as ints still, but other types are deleted as a pointer casted to its type.
Last edited on
Topic archived. No new replies allowed.