Same. They are good for connecting data parts but I also like to use them as identifiers (the address) nstead of coming up with my own. I found the approach to be more flexible.
It's mostly when dealing with set-like containers (key-value is the pointer type), or acquiring some associated data/object. For persistent stuff like serialization, what I do is to have some hierarchical format that describes which data parts are being referred to by it, usually by simply reflecting the code itself so you have struct layout saved alongside data in some associative manner. From that I reconstruct data/object during deserialization using the saved (now invalid) pointers as ref. keys to bind newly created stuff together. It might sound complicated but once you have that done you no longer need to really bother with even persistent IDs anymore, the code itself does your job for you.
ok, when you reserialize the data, do you end up having to overwrite any that is not directly related to what you changed?
what about scaling to multiple machines?
>do you end up having to overwrite any that is not directly related to what you changed?
Is that related to the pointer talk? I feel like this is a separate issue where you basically just need some data versioning.
>what about scaling to multiple machines
You mean 64 vs 32-bit address map? It not really a problem if the deserializer just recreates the data and uses file addresses as a reference keys.
when you have a function that allocates/works with data of an arbitrary/unknown type, like malloc, which return a void pointer
I've only had to use it a couple of times in my own code tho, usually when working with weird non standard datatypes
I vaguely recall using it when I wanted to do pointer offsets that did not align with the size of the datatype I was working with
Though for the life of me I can't remember why I wanted to do that
one example of where it's commonly used in c is when you have "userdata". For example if a function takes a callback function and you want to be able to pass your own data to the function. Or if there is a struct in a library and you want to be able to add custom data to that struct so you can associate more data with it. If you dont do that then you would need a global hash map that uses the structure pointer as a key and your custom data as a value.
Gtk for example uses void* for callback function and structs.
not really. that would mean it can determine the type pointed to automatically, which isn't the case. while any pointer can become a void pointer, the void pointer requires explicit cast to be converted (or reinterpret_cast in c++). if you know java, it's the equivalent of having an Object reference. has a few use cases, but 99% of the time you don't use it if you're not a retard.
c still a naggerlicious language though
Same. They are good for connecting data parts but I also like to use them as identifiers (the address) nstead of coming up with my own. I found the approach to be more flexible.
please explain more how you use them as identifiers.
I seriously hope you are not using them as persistent identifiers.
It's mostly when dealing with set-like containers (key-value is the pointer type), or acquiring some associated data/object. For persistent stuff like serialization, what I do is to have some hierarchical format that describes which data parts are being referred to by it, usually by simply reflecting the code itself so you have struct layout saved alongside data in some associative manner. From that I reconstruct data/object during deserialization using the saved (now invalid) pointers as ref. keys to bind newly created stuff together. It might sound complicated but once you have that done you no longer need to really bother with even persistent IDs anymore, the code itself does your job for you.
ok, when you reserialize the data, do you end up having to overwrite any that is not directly related to what you changed?
what about scaling to multiple machines?
It basically looks like this.
@0x0 "MyStruct": {
@0x0 "int x": 1,
@0x4 "int* ptr:" 0x1000
}
@0x1000 "int": 2
@0x20 "Storage" {
@0x20 "MyStruct[20] myStructs":{{2, 0x1000}, {4, 0x1000}}
}
>do you end up having to overwrite any that is not directly related to what you changed?
Is that related to the pointer talk? I feel like this is a separate issue where you basically just need some data versioning.
>what about scaling to multiple machines
You mean 64 vs 32-bit address map? It not really a problem if the deserializer just recreates the data and uses file addresses as a reference keys.
I don't
why not?
I lied
They absolutely have their uses and I like them (for now), but I rarely use c++ and haven't shot my leg off with it yet
>void *
how does that work?
it's a pointer to memory with no defined type
when would you ever use this?
when you have a function that allocates/works with data of an arbitrary/unknown type, like malloc, which return a void pointer
I've only had to use it a couple of times in my own code tho, usually when working with weird non standard datatypes
I vaguely recall using it when I wanted to do pointer offsets that did not align with the size of the datatype I was working with
Though for the life of me I can't remember why I wanted to do that
Meant for
one example of where it's commonly used in c is when you have "userdata". For example if a function takes a callback function and you want to be able to pass your own data to the function. Or if there is a struct in a library and you want to be able to add custom data to that struct so you can associate more data with it. If you dont do that then you would need a global hash map that uses the structure pointer as a key and your custom data as a value.
Gtk for example uses void* for callback function and structs.
>dynamically typed pointers
naggerlicious language
not really. that would mean it can determine the type pointed to automatically, which isn't the case. while any pointer can become a void pointer, the void pointer requires explicit cast to be converted (or reinterpret_cast in c++). if you know java, it's the equivalent of having an Object reference. has a few use cases, but 99% of the time you don't use it if you're not a retard.
c still a naggerlicious language though
No, you have to cast it to a type to actually do anything with it
>segmented far pointers
>use C# so don't have to learn about pointers
>*null reference exception blocks your path*
pointers are easy to learn when you think of character and string arrays
Why? What's your point?
6 inches
If you ever get an actual job you'll quickly change your mind about them.