How to Declare a C++ Function that Takes a Blob of Memory? 0 ▲ Giovanni Dicanio's Blog 176 days ago · Tech · hide · Fediverse post An interesting question you may ask in C++ is: “How would you declare a function that takes a blob of memory as input?” For example, think of a function that hashes some input data (using SHA-256, or whatever hash algorithm), or a function that takes some binary data and writes that to disk. Coming from my C background, an option that came to mind would certainly be: void DoSomething(const void* p, size_t numBytes) You simply pass a const void* pointer to the beginning of the input memory block, and the total size of the memory block, expressed in bytes. Then, some C++ programmer could start complaining: “Hey, why do you use the unsafe old C-style void* pointer? Use some safe explicit type like uint8_t, which clearly represents an 8-bit byte!”. So, they propose to “step up” to the following prototype: void DoSomething(const uint8_t* p, size_t numBytes) Now, suppose that you want to pass to this function a custom structure, like this: struct MyCustomData { ... }; MyCustomData data;… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town