view man/xemacs/regs.texi @ 5157:1fae11d56ad2

redo memory-usage mechanism, add way of dynamically initializing Lisp objects -------------------- ChangeLog entries follow: -------------------- lisp/ChangeLog addition: 2010-03-18 Ben Wing <ben@xemacs.org> * diagnose.el (show-memory-usage): Rewrite to take into account API changes in memory-usage functions. src/ChangeLog addition: 2010-03-18 Ben Wing <ben@xemacs.org> * alloc.c: * alloc.c (disksave_object_finalization_1): * alloc.c (lisp_object_storage_size): * alloc.c (listu): * alloc.c (listn): * alloc.c (Fobject_memory_usage_stats): * alloc.c (compute_memusage_stats_length): * alloc.c (Fobject_memory_usage): * alloc.c (Ftotal_object_memory_usage): * alloc.c (malloced_storage_size): * alloc.c (common_init_alloc_early): * alloc.c (reinit_alloc_objects_early): * alloc.c (reinit_alloc_early): * alloc.c (init_alloc_once_early): * alloc.c (syms_of_alloc): * alloc.c (reinit_vars_of_alloc): * buffer.c: * buffer.c (struct buffer_stats): * buffer.c (compute_buffer_text_usage): * buffer.c (compute_buffer_usage): * buffer.c (buffer_memory_usage): * buffer.c (buffer_objects_create): * buffer.c (syms_of_buffer): * buffer.c (vars_of_buffer): * console-impl.h (struct console_methods): * dynarr.c (Dynarr_memory_usage): * emacs.c (main_1): * events.c (clear_event_resource): * extents.c: * extents.c (compute_buffer_extent_usage): * extents.c (extent_objects_create): * extents.h: * faces.c: * faces.c (compute_face_cachel_usage): * faces.c (face_objects_create): * faces.h: * general-slots.h: * glyphs.c: * glyphs.c (compute_glyph_cachel_usage): * glyphs.c (glyph_objects_create): * glyphs.h: * lisp.h: * lisp.h (struct usage_stats): * lrecord.h: * lrecord.h (enum lrecord_type): * lrecord.h (struct lrecord_implementation): * lrecord.h (MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE): * lrecord.h (DEFINE_DUMPABLE_LISP_OBJECT): * lrecord.h (DEFINE_DUMPABLE_SIZABLE_LISP_OBJECT): * lrecord.h (DEFINE_DUMPABLE_FROB_BLOCK_LISP_OBJECT): * lrecord.h (DEFINE_DUMPABLE_FROB_BLOCK_SIZABLE_LISP_OBJECT): * lrecord.h (DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT): * lrecord.h (DEFINE_DUMPABLE_SIZABLE_INTERNAL_LISP_OBJECT): * lrecord.h (DEFINE_NODUMP_LISP_OBJECT): * lrecord.h (DEFINE_NODUMP_SIZABLE_LISP_OBJECT): * lrecord.h (DEFINE_NODUMP_FROB_BLOCK_LISP_OBJECT): * lrecord.h (DEFINE_NODUMP_FROB_BLOCK_SIZABLE_LISP_OBJECT): * lrecord.h (DEFINE_NODUMP_INTERNAL_LISP_OBJECT): * lrecord.h (DEFINE_NODUMP_SIZABLE_INTERNAL_LISP_OBJECT): * lrecord.h (MAKE_LISP_OBJECT): * lrecord.h (DEFINE_DUMPABLE_MODULE_LISP_OBJECT): * lrecord.h (DEFINE_DUMPABLE_MODULE_SIZABLE_LISP_OBJECT): * lrecord.h (DEFINE_NODUMP_MODULE_LISP_OBJECT): * lrecord.h (DEFINE_NODUMP_MODULE_SIZABLE_LISP_OBJECT): * lrecord.h (MAKE_MODULE_LISP_OBJECT): * lrecord.h (INIT_LISP_OBJECT): * lrecord.h (INIT_MODULE_LISP_OBJECT): * lrecord.h (UNDEF_LISP_OBJECT): * lrecord.h (UNDEF_MODULE_LISP_OBJECT): * lrecord.h (DECLARE_LISP_OBJECT): * lrecord.h (DECLARE_MODULE_API_LISP_OBJECT): * lrecord.h (DECLARE_MODULE_LISP_OBJECT): * lstream.c: * lstream.c (syms_of_lstream): * lstream.c (vars_of_lstream): * marker.c: * marker.c (compute_buffer_marker_usage): * mc-alloc.c (mc_alloced_storage_size): * mc-alloc.h: * mule-charset.c: * mule-charset.c (struct charset_stats): * mule-charset.c (compute_charset_usage): * mule-charset.c (charset_memory_usage): * mule-charset.c (mule_charset_objects_create): * mule-charset.c (syms_of_mule_charset): * mule-charset.c (vars_of_mule_charset): * redisplay.c: * redisplay.c (compute_rune_dynarr_usage): * redisplay.c (compute_display_block_dynarr_usage): * redisplay.c (compute_glyph_block_dynarr_usage): * redisplay.c (compute_display_line_dynarr_usage): * redisplay.c (compute_line_start_cache_dynarr_usage): * redisplay.h: * scrollbar-gtk.c (gtk_compute_scrollbar_instance_usage): * scrollbar-msw.c (mswindows_compute_scrollbar_instance_usage): * scrollbar-x.c (x_compute_scrollbar_instance_usage): * scrollbar.c (compute_scrollbar_instance_usage): * scrollbar.h: * symbols.c: * symbols.c (reinit_symbol_objects_early): * symbols.c (init_symbols_once_early): * symbols.c (reinit_symbols_early): * symbols.c (defsymbol_massage_name_1): * symsinit.h: * ui-gtk.c: * ui-gtk.c (emacs_gtk_object_getprop): * ui-gtk.c (emacs_gtk_object_putprop): * ui-gtk.c (ui_gtk_objects_create): * unicode.c (compute_from_unicode_table_size_1): * unicode.c (compute_to_unicode_table_size_1): * unicode.c (compute_from_unicode_table_size): * unicode.c (compute_to_unicode_table_size): * window.c: * window.c (struct window_stats): * window.c (compute_window_mirror_usage): * window.c (compute_window_usage): * window.c (window_memory_usage): * window.c (window_objects_create): * window.c (syms_of_window): * window.c (vars_of_window): * window.h: Redo memory-usage mechanism, make it general; add way of dynamically initializing Lisp object types -- OBJECT_HAS_METHOD(), similar to CONSOLE_HAS_METHOD(). (1) Create OBJECT_HAS_METHOD(), OBJECT_HAS_PROPERTY() etc. for specifying that a Lisp object type has a particular method or property. Call such methods with OBJECT_METH, MAYBE_OBJECT_METH, OBJECT_METH_OR_GIVEN; retrieve properties with OBJECT_PROPERTY. Methods that formerly required a DEFINE_*GENERAL_LISP_OBJECT() to specify them (getprop, putprop, remprop, plist, disksave) now instead use the dynamic-method mechanism. The main benefit of this is that new methods or properties can be added without requiring that the declaration statements of all existing methods be modified. We have to make the `struct lrecord_implementation' non-const, but I don't think this should have any effect on speed -- the only possible method that's really speed-critical is the mark method, and we already extract those out into a separate (non-const) array for increased cache locality. Object methods need to be reinitialized after pdump, so we put them in separate functions such as face_objects_create(), extent_objects_create() and call them appropriately from emacs.c The only current object property (`memusage_stats_list') that objects can specify is a Lisp object and gets staticpro()ed so it only needs to be set during dump time, but because it references symbols that might not exist in a syms_of_() function, we initialize it in vars_of_(). There is also an object property (`num_extra_memusage_stats') that is automatically initialized based on `memusage_stats_list'; we do that in reinit_vars_of_alloc(), which is called after all vars_of_() functions are called. `disksaver' method was renamed `disksave' to correspond with the name normally given to the function (e.g. disksave_lstream()). (2) Generalize the memory-usage mechanism in `buffer-memory-usage', `window-memory-usage', `charset-memory-usage' into an object-type- specific mechanism called by a single function `object-memory-usage'. (Former function `object-memory-usage' renamed to `total-object-memory-usage'). Generalize the mechanism of different "slices" so that we can have different "classes" of memory described and different "slices" onto each class; `t' separates classes, `nil' separates slices. Currently we have three classes defined: the memory of an object itself, non-Lisp-object memory associated with the object (e.g. arrays or dynarrs stored as fields in the object), and Lisp-object memory associated with the object (other internal Lisp objects stored in the object). This isn't completely finished yet and we might need to further separate the "other internal Lisp objects" class into two classes. The memory-usage mechanism uses a `struct usage_stats' (renamed from `struct overhead_stats') to describe a malloc-view onto a set of allocated memory (listing how much was requested and various types of overhead) and a more general `struct generic_usage_stats' (with a `struct usage_stats' in it) to hold all statistics about object memory. `struct generic_usage_stats' contains an array of 32 Bytecounts, which are statistics of unspecified semantics. The intention is that individual types declare a corresponding struct (e.g. `struct window_stats') with the same structure but with specific fields in place of the array, corresponding to specific statistics. The number of such statistics is an object property computed from the list of tags (Lisp symbols describing the statistics) stored in `memusage_stats_list'. The idea here is to allow particular object types to customize the number and semantics of the statistics where completely avoiding consing. This doesn't matter so much yet, but the intention is to have the memory usage of all objects computed at the end of GC, at the same time as other statistics are currently computed. The values for all statistics for a single type would be added up to compute aggregate values for all objects of a specific type. To make this efficient, we can't allow any memory allocation at all. (3) Create some additional functions for creating lists that specify the elements directly as args rather than indirectly through an array: listn() (number of args given), listu() (list terminated by Qunbound). (4) Delete a bit of remaining unused C window_config stuff, also unused lrecord_type_popup_data.
author Ben Wing <ben@xemacs.org>
date Thu, 18 Mar 2010 10:50:06 -0500
parents 74fd4e045ea6
children 697ef44129c6
line wrap: on
line source


@node Registers, Display, Rectangles, Top
@chapter Registers
@cindex registers

  XEmacs @dfn{registers} are places in which you can save text or
positions for later use.  Once you save text or a rectangle in a
register, you can copy it into the buffer once or many times; a position
saved in a register is used by moving point to that position.
Rectangles can also be copied into and out of registers
(@pxref{Rectangles}).

@findex view-register
  Each register has a name which is a single character.  A register can
store a piece of text, a rectangle, a position, a window configuration,
or a file name, but only one thing at any given time.  Whatever you
store in a register remains there until you store something else in that
register.  To see what a register @var{r} contains, use @kbd{M-x
view-register}.

@table @kbd
@item M-x view-register @key{RET} @var{r}
Display a description of what register @var{r} contains.
@end table

@findex view-register
  @kbd{M-x view-register} reads a register name as an argument and then
displays the contents of the specified register.

@menu
* Position: RegPos.           Saving positions in registers.
* Text: RegText.              Saving text in registers.
* Rectangle: RegRect.         Saving rectangles in registers.
* Configurations: RegConfig.  Saving window configurations in registers.
* Files: RegFiles.            File names in registers.
* Numbers: RegNumbers.        Numbers in registers.
* Bookmarks::                 Bookmarks are like registers, but persistent.
@end menu

@node RegPos, RegText, Registers, Registers
@section Saving Positions in Registers

  Saving a position records a place in a buffer so that you can move
back there later.  Moving to a saved position switches to that buffer
and moves point to that place in it.

@table @kbd
@item C-x r @key{SPC} @var{r}
Save position of point in register @var{r} (@code{point-to-register}).
@item C-x r j @var{r}
Jump to the position saved in register @var{r} (@code{jump-to-register}).
@end table

@kindex C-x r SPC
@findex point-to-register
  To save the current position of point in a register, choose a name
@var{r} and type @kbd{C-x r @key{SPC} @var{r}}.  The register @var{r}
retains the position thus saved until you store something else in that
register.

@kindex C-x r j
@findex jump-to-register
  The command @kbd{C-x r j @var{r}} moves point to the position recorded
in register @var{r}.  The register is not affected; it continues to
record the same location.  You can jump to the same position using the
same register as often as you want.

  If you use @kbd{C-x r j} to go to a saved position, but the buffer it
was saved from has been killed, @kbd{C-x r j} tries to create the buffer
again by visiting the same file.  Of course, this works only for buffers
that were visiting files.

@node RegText, RegRect, RegPos, Registers
@section Saving Text in Registers

  When you want to insert a copy of the same piece of text many times, it
can be impractical to use the kill ring, since each subsequent kill moves
the piece of text further down on the ring.  It becomes hard to keep
track of the argument needed to retrieve the same text with @kbd{C-y}.  An
alternative is to store the text in a register with @kbd{C-x r s}
(@code{copy-to-register}) and then retrieve it with @kbd{C-x r i}
(@code{insert-register}).

@table @kbd
@item C-x r s @var{r}
Copy region into register @var{r} (@code{copy-to-register}).
@item C-x r g @var{r}
@itemx C-x r i @var{r}
Insert text contents of register @var{r} (@code{insert-register}).
@end table

@kindex C-x r s
@kindex C-x r g
@kindex C-x r i
@findex copy-to-register
@findex insert-register
  @kbd{C-x r s @var{r}} stores a copy of the text of the region into the
register named @var{r}.  Given a numeric argument, @kbd{C-x r s @var{r}}
deletes the text from the buffer as well.

  @kbd{C-x r i @var{r}} inserts the text from register @var{r} in the buffer.
By default it leaves point before the text and places the mark after
it. With a numeric argument (@kbd{C-u}), it puts point after the text
and the mark before it.

@node RegRect, RegConfig, RegText, Registers
@section Saving Rectangles in Registers
@cindex rectangle

  A register can contain a rectangle instead of lines of text.  The rectangle
is represented as a list of strings.  @xref{Rectangles}, for basic
information on rectangles and how to specify rectangles in a buffer.

@table @kbd
@findex copy-rectangle-to-register
@kindex C-x r r
@item C-x r r @var{r}
Copy the region-rectangle into register @var{r}
(@code{copy-rectangle-to-register}).  With a numeric argument, delete it
as well.
@item C-x r g @var{r}
@itemx C-x r i @var{r}
Insert the rectangle stored in register @var{r} (if it contains a
rectangle) (@code{insert-register}).
@end table

  The @kbd{C-x r i @var{r}} command inserts linear text if the register
  contains
that, or inserts a rectangle if the register contains one.

  See also the command @code{sort-columns}, which you can think of
as sorting a rectangle.  @xref{Sorting}.

@node RegConfig, RegNumbers, RegRect, Registers
@section Saving Window Configurations in Registers

@findex window-configuration-to-register
@findex frame-configuration-to-register
@kindex C-x r w
@c @kindex C-x r f
  You can save the window configuration of the selected frame in a
register, or even the configuration of all windows in all frames, and
restore the configuration later.

@table @kbd
@item C-x r w @var{r}
Save the state of the selected frame's windows in register @var{r}
(@code{window-configuration-to-register}).
@c @item C-x r f @var{r}
@item M-x frame-configuration-to-register @key{RET} @var{r}
Save the state of all frames, including all their windows, in register
@var{r} (@code{frame-configuration-to-register}).
@end table

  Use @kbd{C-x r j @var{r}} to restore a window or frame configuration.
This is the same command used to restore a cursor position.  When you
restore a frame configuration, any existing frames not included in the
configuration become invisible.  If you wish to delete these frames
instead, use @kbd{C-u C-x r j @var{r}}.

@node RegNumbers, RegFiles, RegConfig, Registers
@section Keeping Numbers in Registers

  There are commands to store a number in a register, to insert
the number in the buffer in decimal, and to increment it.  These commands
can be useful in keyboard macros (@pxref{Keyboard Macros}).

@table @kbd
@item C-u @var{number} C-x r n @var{reg}
@kindex C-x r n
@findex number-to-register
Store @var{number} into register @var{reg} (@code{number-to-register}).
@item C-u @var{number} C-x r + @var{reg}
@kindex C-x r +
@findex increment-register
Increment the number in register @var{reg} by @var{number}
(@code{increment-register}).
@item C-x r g @var{reg}
Insert the number from register @var{reg} into the buffer.
@end table

  @kbd{C-x r g} is the same command used to insert any other
sort of register contents into the buffer.

@node RegFiles, Bookmarks, RegNumbers, Registers
@section Keeping File Names in Registers

  If you visit certain file names frequently, you can visit them more
conveniently if you put their names in registers.  Here's the Lisp code
used to put a file name in a register:

@smallexample
(set-register ?@var{r} '(file . @var{name}))
@end smallexample

@need 3000
@noindent
For example,

@smallexample
(set-register ?z '(file . "/usr/src/xemacs/src/ChangeLog"))
@end smallexample

@noindent
puts the file name shown in register @samp{z}.

  To visit the file whose name is in register @var{r}, type @kbd{C-x r j
@var{r}}.  (This is the same command used to jump to a position or
restore a frame configuration.)

@node Bookmarks,  , RegFiles, Registers
@section Bookmarks
@cindex bookmarks

  @dfn{Bookmarks} are somewhat like registers in that they record
positions you can jump to.  Unlike registers, they have long names, and
they persist automatically from one Emacs session to the next.  The
prototypical use of bookmarks is to record ``where you were reading'' in
various files.

  Note: bookmark.el is distributed in edit-utils package.  You need to
install that to use bookmark facility (@pxref{Packages}).

@table @kbd
@item C-x r m @key{RET}
Set the bookmark for the visited file, at point.

@item C-x r m @var{bookmark} @key{RET}
@findex bookmark-set
Set the bookmark named @var{bookmark} at point (@code{bookmark-set}).

@item C-x r b @var{bookmark} @key{RET}
@findex bookmark-jump
Jump to the bookmark named @var{bookmark} (@code{bookmark-jump}).

@item C-x r l
@findex list-bookmarks
List all bookmarks (@code{list-bookmarks}).

@item M-x bookmark-save
@findex bookmark-save
Save all the current bookmark values in the default bookmark file.
@end table

@kindex C-x r m
@findex bookmark-set
@kindex C-x r b
@findex bookmark-jump
  The prototypical use for bookmarks is to record one current position
in each of several files.  So the command @kbd{C-x r m}, which sets a
bookmark, uses the visited file name as the default for the bookmark
name.  If you name each bookmark after the file it points to, then you
can conveniently revisit any of those files with @kbd{C-x r b}, and move
to the position of the bookmark at the same time.

@kindex C-x r l
  To display a list of all your bookmarks in a separate buffer, type
@kbd{C-x r l} (@code{list-bookmarks}).  If you switch to that buffer,
you can use it to edit your bookmark definitions or annotate the
bookmarks.  Type @kbd{C-h m} in that buffer for more information about
its special editing commands.

  When you kill XEmacs, XEmacs offers to save your bookmark values in
your default bookmark file, @file{~/.emacs.bmk}, if you have changed any
bookmark values.  You can also save the bookmarks at any time with the
@kbd{M-x bookmark-save} command.  The bookmark commands load your
default bookmark file automatically.  This saving and loading is how
bookmarks persist from one XEmacs session to the next.

@vindex bookmark-save-flag
  If you set the variable @code{bookmark-save-flag} to 1, then each
command that sets a bookmark will also save your bookmarks; this way,
you don't lose any bookmark values even if XEmacs crashes.  (The value,
if a number, says how many bookmark modifications should go by between
saving.)

@vindex bookmark-search-size
  Bookmark position values are saved with surrounding context, so that
@code{bookmark-jump} can find the proper position even if the file is
modified slightly.  The variable @code{bookmark-search-size} says how
many characters of context to record, on each side of the bookmark's
position.

  Here are some additional commands for working with bookmarks:

@table @kbd
@item M-x bookmark-load @key{RET} @var{filename} @key{RET}
@findex bookmark-load
Load a file named @var{filename} that contains a list of bookmark
values.  You can use this command, as well as @code{bookmark-write}, to
work with other files of bookmark values in addition to your default
bookmark file.

@item M-x bookmark-write @key{RET} @var{filename} @key{RET}
@findex bookmark-write
Save all the current bookmark values in the file @var{filename}.

@item M-x bookmark-delete @key{RET} @var{bookmark} @key{RET}
@findex bookmark-delete
Delete the bookmark named @var{bookmark}.

@item M-x bookmark-insert-location @key{RET} @var{bookmark} @key{RET}
@findex bookmark-insert-location
Insert in the buffer the name of the file that bookmark @var{bookmark}
points to.

@item M-x bookmark-insert @key{RET} @var{bookmark} @key{RET}
@findex bookmark-insert
Insert in the buffer the @emph{contents} of the file that bookmark
@var{bookmark} points to.
@end table