In J, memory is obtained from the system via malloc() and returned to the system via free(). In addition, there are pools for small (<: 1024 bytes) blocks; a pool is built by malloc()ing 64KB and subdivided into blocks of the same size. In the following, "memory is allocated" means memory obtained via malloc() or by getting it from the small blocks pool, and "memory is released" means memory released via free() or by putting it back into the small blocks pool.
The interpreter contains the 3 word-size names BYTES, BYTESTOT, and BYTESMAX. BYTES is incremented when memory is allocated and decremented when memory is released. BYTES is unchanged when memory is malloc()ed to build a small blocks pool or when memory from the small blocks pool is free()d. 7!:0 returns the current value of BYTES. BYTESTOT is incremented when memory is allocated. 7!:1 returns the current value of BYTESTOT. BYTESTOT is not that useful (some may even say it's useless) because the incrementation is done without regards to integer overflow and so BYTESTOT can be negative. In general BYTESTOT only tells you the total memory allocation modulo the word size (can not distinguish between total allocation of n or n+m*2^32 or n+m*2^64). Repeated execution of the following expression illustrates this point: 3 : 'for. i. y do. #i.1e7 end. 7!:1 $0' 10 BYTESMAX is used in 7!:2 (space needed to execute) as follows: BYTESMAX = k = BYTES; execute the expression return BYTESMAX - k; And, when memory is allocated, after BYTES has been incremented, BYTESMAX = max(BYTESMAX,BYTES); So what 7!:2 gives you is the high water mark in memory allocated during the execution of an expression. 7!:3 is as described in the dictionary page http://www.jsoftware.com/help/dictionary/dx007.htm It gives the number of blocks of each size in the small blocks pool. I believe that this and my msg earlier today on the same subject have answered all your questions. ----- Original Message ----- From: "Sherlock, Ric" <[EMAIL PROTECTED]> Date: Tuesday, July 29, 2008 21:30 Subject: [Jgeneral] Space foreign conjunctions To: General forum <[email protected]> > I'm trying to understand how the various 7!:n foreign > conjunctions relate to each other and to the memory use reported > by Windows Task Manager. I apologise in advance if any of the > questions below illustrate my meagre understanding of memory usage. > > >From the Dictionary (help/dictionary/dx007.htm) > 7!:0 Current. Space currently in use. > 7!:3 Free Space. ... 2-column table of the block sizes and > number of free blocks for each size. > 7!:6 Locale Space. The space in bytes used by the locales named > in y , including the space for the names as well as values in > the locale, locale name, path, hash table, and global symbol > table entries. > > My understanding from reading through the posts linked here: > http://www.jsoftware.com/jwiki/Guides/General_FAQ/How_does_J_manage_memory%3F > > ..is that the space described by 7!:3 is allocated to and > managed by J (not available to the operating system), but not > currently "used" by J. > > A) Is Free Space included in, or on top of Current space ? > > ]LocSpc=: +/ 7!:6 conl '' > 1218784 > ]FreeBlks=: 7!:3 '' > 64 1411 > 128 602 > 256 303 > 512 109 > 1024 21 > ]FreeSpc=: +/ */"1 FreeBlks > 322240 > ]InuseSpc=: 7!:0 '' > 1465472 > > InuseSpc-LocSpc+FreeSpc > _75552 > ...suggests that it is on top of 7!:0 '', > > B) Assuming Free Space is on top of Current Space, what else is > included in Current Space apart from Locale Space? > > InuseSpc-LocSpc > 246688 > > Again assuming that FreeSpc is on top of InuseSpc, total space > allocated to J in kilobytes is: > 1024%~ InuseSpc+FreeSpc > 1745.8125 > Windows Task Manager reports 3,800 K in use. > > C) Is the difference between Current Space + Free Space and what > the Task Manager reports due to (from Dec 2001 forum post) > "interpreter memory use including things like primitives and > locales (symbol tables and namespaces)" ? > > 7!:1 Session. Total space used since start of session. > > D) Is Session Space equal to Current space + all space allocated > and then freed since the start of session? ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
