MCPcopy Index your code
hub / github.com/NetHack/NetHack / alloc_itermonarr

Function alloc_itermonarr

src/mon.c:4470–4490  ·  view source on GitHub ↗

manage itermonarr; it used to be allocated and freed every time the monster movement loop ran; now, keep it around most of the time */

Source from the content-addressed store, hash-verified

4468/* manage itermonarr; it used to be allocated and freed every time the
4469 monster movement loop ran; now, keep it around most of the time */
4470void
4471alloc_itermonarr(unsigned count)
4472{
4473 /* if count is 0 or bigger than itermonsiz or much smaller than
4474 itermonsiz, release itermonarr (and reset itermonsiz to 0) */
4475 if (!count || count > itermonsiz || count + 40 < itermonsiz) {
4476 if (itermonarr)
4477 free((genericptr_t) itermonarr), itermonarr = NULL;
4478 itermonsiz = 0;
4479 }
4480 /* when count is more than itermonsiz (including when that just
4481 got reset to 0), allocate a new instance of itermonarr;
4482 implies that count is greater than 0 */
4483 if (count > itermonsiz) {
4484 /* overallocate to reduce free/alloc-again thrashing when the
4485 number of monsters varies from turn to turn */
4486 itermonsiz = count + 20;
4487 itermonarr = (struct monst **) alloc(
4488 itermonsiz * sizeof (struct monst *));
4489 }
4490}
4491
4492/* Iterate all monsters on the level, even dead or off-map ones, calling
4493 bfunc() for each monster. If bfunc() returns TRUE, stop iterating.

Callers 2

iter_mons_safeFunction · 0.85
freedynamicdataFunction · 0.85

Calls 1

allocFunction · 0.70

Tested by

no test coverage detected