A struct would /be/ an object, thus its overhead would be the same as for a class, because in Java, a class *is* a struct, or to put it another way, there is no such thing as a "struct", and if there were, it would be an object. How do you think you can create an object for free by calling it a "struct"?
As for trying to optimize object creation and GC, what makes you think that poses a problem for you? Where is your evidence - your profiles, timing measurements and description of the loads and other conditions under which you tested them? And if you have such masurements, which I sincerely doubt, how would using a "struct" have any remote possibility of improving on that? Don't waste your time looking for solutions to non-existent problems. -- Lew On Thursday, November 24, 2011 5:54:07 AM UTC-8, Aitor Mendaza Ormaza wrote: > > > On Thu, Nov 24, 2011 at 2:18 PM, Mark Murphy <[email protected]>wrote: > >> http://java.sun.com/developer/Books/shiftintojava/page1.html >> >> "Upon first exposure to the Java programming language, some C >> programmers believe that classes are too heavyweight to replace >> structs under some circumstances, but this is not the case. Degenerate >> classes consisting solely of data fields are nearly equivalent to C >> structs in every respect." >> >> If you choose not to believe Mr. Bloch, that is your decision. >> >> > http://developer.android.com/guide/practices/design/performance.html > > "Object creation is never free. A generational GC with per-thread > allocation pools for temporary objects can make allocation cheaper, but > allocating memory is always more expensive than not allocating memory. > > If you allocate objects in a user interface loop, you will force a > periodic garbage collection, creating little "hiccups" in the user > experience. The concurrent collector introduced in Gingerbread helps, but > unnecessary work should always be avoided." > > > For what is worth, I don't choose not to believe Mr. Bloch, I was just > wondering if in Android were better choices for classes as structs, as I > know my knowledge of both Java and Android is limited. That's the reason I > asked here after searching the web with no results (again, maybe my results > weren't good enough to get the answers I was looking for). > > Thanks, though, for the link, as it seems interesting. > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

