Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Expanding array

Author
Message
Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 22nd Dec 2008 07:39
Alright, I'm trying to make a dynamic array.

The concept itself works. I can delete certain elements of the array just fine, but when I add to the array... I get garbage in spots that I know shouldn't have garbage.

Right after expanding the array, I have it throw debug info to the screen SPECIFICALLY saying that the part of my array with data still HAS that data... but then it immediately goes away!


Here's the code that does just that:



Does anyone see something wrong here that I'm missing?


The one and only,


dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 22nd Dec 2008 15:03
Works fine here, why not just use an std::vector()? Saves a lot of problems. Also when copying an array like that you should just use memcpy(), and I wouldn't personally increment max here '[max++]' as it serves no purpose(when allocating the array that is) and requires you to use 2 pointless subtracts on your loop iteration ranges, you could have just incremented it after that or something, it would make it slightly less ambiguous.

Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 22nd Dec 2008 20:03
The code wasn't meant to be perfect, it was just supposed to be a proof of concept.

And I'm not sure how to use std::vector() like what I'm aiming for.


The one and only,


Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 25th Dec 2008 05:23
Use iterators, vector.begin() and vector.end()...?

Login to post a reply

Server time is: 2024-11-25 09:42:22
Your offset time is: 2024-11-25 09:42:22