Книга: Practical Common Lisp
The last slot option you need to know about is
:allocation. The value of
:allocation can be either
:class and defaults to
:instance if not specified. When a slot has
:class allocation, the slot has only a single value, which is stored in the class and shared by all instances.
:class slots are accessed the same as
:instance slots—they're accessed with
SLOT-VALUE or an accessor function, which means you can access the slot value only through an instance of the class even though it isn't actually stored in the instance. The
:initarg options have essentially the same effect except the initform is evaluated once when the class is defined rather than each time an instance is created. On the other hand, passing an initarg to
MAKE-INSTANCE will set the value, affecting all instances of the class.
Because you can't get at a class-allocated slot without an instance of the class, class-allocated slots aren't really equivalent to static or class fields in languages such as Java, C++, and Python. Rather, class-allocated slots are used primarily to save space; if you're going to create many instances of a class and all instances are going to have a reference to the same object—say, a pool of shared resources—you can save the cost of each instance having its own reference by making the slot class-allocated.
- 17. Object Reorientation: Classes
- InterBase Classic Server под Linux
- Каталог BIN в InterBase Classic Server для Linux
- Classic vs SuperServer
- Рекомендации по выбору архитектуры: Classic или SuperServer?
- Эффективное взаимодействие процессов архитектуры Classic Server
- Yaffil Classic Server - замена InterBase Classic 4.0
- SERVER PRIORITY CLASS
- LOCK HASH SLOTS
- CLASSIFY target