Intermediate 4 Homework Help
Intermediate 4 Homework Help
Hey Forum,
Feels like I'm so nearly there with this, time to reach out before I go ahead and just cheat.
Issue: Can seem to write to a file (can't verify but the file is getting padded with bytes.) but cannot read back successfully. The integers for the value field seem to load back into the array fine but I cannot get the strings to load back and print.
Thingy: https://github.com/SamuelLouisCampbell/intlo.git
Thanks god there's a virus on, getting so much learnin' dun....
Many thanks.
Feels like I'm so nearly there with this, time to reach out before I go ahead and just cheat.
Issue: Can seem to write to a file (can't verify but the file is getting padded with bytes.) but cannot read back successfully. The integers for the value field seem to load back into the array fine but I cannot get the strings to load back and print.
Thingy: https://github.com/SamuelLouisCampbell/intlo.git
Thanks god there's a virus on, getting so much learnin' dun....
Many thanks.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Intermediate 4 Homework Help
Seems to work just fine for me:
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Intermediate 4 Homework Help
Sorry, that must be a link to the master branch (which includes the correct solution from Chili)
https://github.com/SamuelLouisCampbell/ ... ree/SAMDEV
This hopefully links to mine. Thanks!!
https://github.com/SamuelLouisCampbell/ ... ree/SAMDEV
This hopefully links to mine. Thanks!!
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Intermediate 4 Homework Help
Okay, so the issue is you are casting the entire Person struct to a char* and writing out the bytes that make up the struct. Not necessarily a problem if the struct was entirely stack allocated bytes. The char* buffer is just a pointer, so the pointer address is what is stored in the file and not the bytes stored at the address from the previous run of the program.
You must serialize and deserialize the value and string separately or make buffer a c-style array.
You must serialize and deserialize the value and string separately or make buffer a c-style array.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Intermediate 4 Homework Help
The way chili handles it is each entry in the database handles it's own serialization/deserialization. In each of those functions, the value and char* string is written to file.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Intermediate 4 Homework Help
Also, just to point out, Person::setString only copies the address of the source string...not the string itself. You must copy the entire string from source to buffer. The only reason it works somewhat is because NameBufferArray is still in scope. If there was another function where NameBufferArray went out of scope and you tried returning a Person object without making a deep copy of NameBufferArray first, then Person::buffer would point to data that no longer existed.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Intermediate 4 Homework Help
Git pull-request showing you what you could do and explaining why I chose the code I did. Also, there should be a fair amount of comments in the code explaining things.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Intermediate 4 Homework Help
Thanks so much, just sat down to get in a couple of hours coding, I'll be working through your pull request first!
Thanks again for your help, I think I owe you more than a couple of beers now.
Thanks again for your help, I think I owe you more than a couple of beers now.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Intermediate 4 Homework Help
No problem, just wish I could collect...I could use a Corona right about now LOL.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com