aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/photcal/mctable/mctshrink.x
blob: 6a88f2309d8755fc3bf30c5a0f2659293b9c739d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
include	"../lib/mctable.h"


# MCT_SHRINK - Free unused table memory

procedure mct_shrink (table)

pointer	table			# table descriptor

int	lsize, psize

begin
	# Check pointer and magic number.
	if (table == NULL)
	    call error (0, "mct_shrink: Null table pointer")
	if (MCT_MAGIC (table) != MAGIC)
	    call error (0, "mct_shrink: Bad magic number")

	# Compute aproximate logical size, and exact physical
	# sizes. This might produce a little bit of space wasted.

	lsize = MCT_NPROWS (table) * MCT_MAXCOL (table)
	psize = MCT_MAXROW (table) * MCT_MAXCOL (table)

	# Reallocate table sapace and update physical size.
	if (lsize != psize) {
	    call realloc (MCT_DATA (table), lsize, MCT_TYPE (table))
	    MCT_MAXROW  (table) = MCT_NPROWS (table)
	    MCT_INCROWS (table) = GROWFACTOR (MCT_MAXROW (table))
	}
end