Reference Counting in Library Design – Optionally and with Union-Find Optimization Lutz Kettner Max-Planck Institut Informatik Stuhlsatzenhausweg 85 66123 Saarbr ¨ucken, Germany ******@mpi- ABSTRACT Reference counting has been used and described in abun- dance. We present novel ideas aimed at class implementa- tions in library design: (1) In library design, generic classes can have variable size, such that an optimal decision for or against reference counting is not possible. Wepostpone this decision to the place of class use. (2) In a context, where parison for the case of equality is expen- sive, ., for exact algebraic number representations, we unify representationswhenever equality is detected, thus ef- fectively memoizing equality tests. We explain an e?cient implementation based on an union-?nd data structure. (3) Reference counting andpolymorphic class hierarchiescan bined reusing the pointer in the handle class for the polymorphism. A policy-based generic C++solution realizes all manage all dynamic memory. Categories and Subject Descriptors [Programming Techniques]: Miscellaneous General Terms software library design 1. INTRODUCTION Reference counting has been used and described in abun- dance. The principle idea is that a dynamically managed re- source tracks the number of its users in a reference counter. When the count reaches zero the resource can be released. In the context of C++, reference counting is frequently presented for smart pointers and string classes; in both cases managing dynamically allocated memory. I am interested in the principal way it is used in string classes. But, let me contrast it to its use in smart pointers ?rst. Smart pointers monly presented as a solution for ownership and resource management problems that plain C/C++pointers have with dynamically allocated memory. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted witho
陶行知全集 第四卷 诗歌 来自淘豆网m.daumloan.com转载请标明出处.