Tim Allen My CV

December 8, 2015

fun differences betwixt Java and C++ containers

Filed under: programming — tallen @ 10:59 pm

…and for my next rant I wax poetic about the joys of writing code in the morning using C++ containers and in the afternoon switching to Java!

So I’ve got me an array of, I dunno uint32_t’s, and I’m just happy as a clam with my fun member functions and I’m callin’ ’em and I’m doing all sorts of cleverness, and then it comes time to do something with my amusingly arranged array. I need to call something that takes a pointer to an array of uint32_t’ or better yet I need to manipulate my fancy C++ array very quickly. No problem, this is still C isn’t it, bloated and strange but I can still get a pointer, why yes I can. A quick call to array::data() and I get me a pointer to an array of uint32_t’s…but not just any array of uint32_t’s _the_ array, not a copy (that the cpu had to do a shit load of work to make) the real thing… and I can do what I want with this array, may not be wise but I’m good to go!

…and later that day I’m writing some Java; and I got me a SortedSet… clever… arrange… member functions… But now I gotta call some Android crap and it wants an array because it’s going to display it somewhere. So I go to the documentation and I read, “toArray() Returns an array containing all elements contained in this set.” and I’m having flashbacks to this morning and I think jammin! I’ll just use these cutesy member functions to cleverly arrange my set and then I’ll call this refresh (update whatever) method and I already passed Android a reference to the underlying array and viol-la! …and it doesn’t bloody work. Well, it works the first time but I make my member calls on the set and I call refresh and I get the same display I got last time. So I reread the docs, it says, “toArray() Returns an array containing all elements contained in this set,” so what’s the problem… wait for it… Returns an array containing all elements contained in this set not the array. Effing Java decided to copy the whole bloody thing to a new array and then has the temerity to hand me a reference to this useless (and CPU intensive) pile of crap. Arrrgghh, I hate Java. Yeah, yeah, yeah, copy on write whatever, memset this pal!

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress