4 ms·
I considered that. The problem is that memory_block would need an extra pointer to know its size, which seemed like pure waste at that point. And ultimately it
by quicknir 11y ago
I considered that. The problem is that memory_block would need an extra pointer to know its size, which seemed like pure waste at that point. And ultimately it doesn't relieve you of writing copy constructors etc which should be the real goal; it scales much better if you have a class with other members that are not a part of all this contiguous stuff. I hope to solve that in the next post. I think your approach is good as well, just giving you my reasoning for not putting it in.
- efaref 11y agoRather than two pointers I would probably have pointer + len. Storing the length of your arbitrary memory block is no bad thing, imo. In any case, having a sensible copy constructor on the memory_block (and any necessary associated data) would at least make the copy constructors in the client classes (assuming you have more than one user of this pattern) cleaner. It's a really good pattern, though. Excellent blog post.
- quicknir 11y agoThanks, I appreciate that. I welcome your feedback on the follow-up as well.