2009/9/8 Mason Wheeler <@Mason_Wheeler>:
Or I
suppose you could rewrite malloc/new to zero the dynamic memory it
allocates before returning.that would be calloc ( http://www.cppreference.com/wiki/c/mem/calloc )
Yeah. Shame that doesn’t work for objects. (Or is there a cnew operator
I’ve never heard of?)
Objects, on the other hand, tend to be very small. It’s not very common
to see one with an instance size over 200 bytes. (Especially if you don’t
go allocating other large objects or arrays as value types within your
object.)And then you have arrays of objects… or objects allocated and freed
in a loop (generally bad programming, but still pretty common).
I just tested it. Best not to worry about possible performance impacts
unless they’re real bottlenecks, right? So I wrote a quick Delphi app
(Delphi’s object model zeroes out its memory as part of the construction
process) to test a real-world scenario: create a bunch of sprite objects
to populate a game map with, using the same sprite class as I use in
my game engine. I ran a loop through 1 million iterations and had it
report a timestamp before and after.
Total time: 203 miliseconds. Instance size: 132 bytes. (132 MB total)
Most sprites I’ve ever actually instantiated at once under real-world
conditions? A few thousand.
Granted, this is an overpowered premium gaming rig by Alienware, but
results on less powerful systems, such as my last laptop, don’t vary
by all that much. Zeroing a contiguous block of memory, especially
one measured in bytes as opposed to K or MB, is a highly efficient
operation. You can do it 4 bytes at a time, or even faster with SIMD
tricks. The performance hit is negligible enough that you’re not likely
to ever actually notice it.
raises an eyebrow OK, let’s take the program I work on at work. Serious
app. Around 3.5M lines of code. One COM object to work with an external
DLL. One comm subsystem that handles connections with a handful of
middle-tier app servers. Maybe a few dozen synchronization objects, and
of course a few thousand Windows handles for all the GUI stuff, user input,
and a little bit of file handling. And hundreds of thousands of objects that
get allocated in process memory. The middle-tier servers look a lot like
that, too. A bit more comm stuff, a whole lot less GUI, but a similar
overall distribution. And I don’t think there are very many apps that don’t
look like that.Not many programs make it to 3.5 million lines of code… In a
smaller program, I expect a much larger proportion of code and memory
would be devoted to GUI, I/O, networking and system calls, or whatever
libraries it’s using. It would also vary greatly by the type of
program you’re writing.
Well, the editor for the game engine I’m working on currently weighs in at
around 200k lines of code total. Much less GUI than the enterprise-level app
at work, (about 10 forms instead of a few hundred), no networking (yet), a
fair amount of file handling, including a plugin system, and an SDL interface
to display the graphics. And thousands of objects and arrays.
I can really only see external resources becoming a significant fraction of
total resources if you scale it way down to trivial apps. Windows
Calculator, for example, which has a fairly involved GUI in Scientific mode
but almost no need for state.>----- Original Message ----
From: Kenneth Bull
Subject: Re: [SDL] Rewrite input system for hot-plugging