skip to main content
article
Open Access

Efficient implementation of the first-fit strategy for dynamic storage allocation

Published:01 July 1989Publication History
Skip Abstract Section

Abstract

We describe an algorithm that efficiently implements the first-fit strategy for dynamic storage allocation. The algorithm imposes a storage overhead of only one word per allocated block (plus a few percent of the total space used for dynamic storage), and the time required to allocate or free a block is O(log W), where W is the maximum number of words allocated dynamically. The algorithm is faster than many commonly used algorithms, especially when many small blocks are allocated, and has good worst-case behavior. It is relatively easy to implement and could be used internally by an operating system or to provide run-time support for high-level languages such as Pascal and Ada. A Pascal implementation is given in the Appendix.

References

  1. 1 BAYS, C. A comparison of next-fit, first-fit and best-fit. Commun. ACM 20, 3 (Mar. 1977), 191-192. Google ScholarGoogle Scholar
  2. 2 BOZMAN, G. The software lookaside buffer reduces search overhead with linked lists. Commun. ACM 27, 3 (Mar. 1984), 222-227. Google ScholarGoogle Scholar
  3. 3 BOZMAN, G., BUCO, W., DALY, T. P., ANO TETZLAFF, W. H. Analysis of free-storage algo-{ rithms--revisited. IBM Syst. J. 23, 1 (1984), 44-64.Google ScholarGoogle Scholar
  4. 4 BRENT, R.P. Efficient implementation of the first-fit strategy for dynamic storage allocation. Australian Comput. Sci. Commun. 3, 1 (May 1981), 25-34.Google ScholarGoogle Scholar
  5. 5 BRENT, R.P. Efficient implementation of the first-fit strategy for dynamic storage allocation. Rep. CMA-R33-84, Centre for Mathematical Analysis, Australian National University, Aug. 1984.Google ScholarGoogle Scholar
  6. 6 BRENT, R.P. Dynamic storage allocation on a computer with virtual memory. Rep. CMA-R37- 84, Centre for Mathematical Analysis, Australian National University, Sept. 1984.Google ScholarGoogle Scholar
  7. 7 Fox, P. A., HALL, A. D., AND SCHRYER, N.L. The PORT mathematical subroutine library, ACM Trans. Math. Softw. 4, 2 (June 1978), 104-126. Google ScholarGoogle Scholar
  8. 8 GEROVAC, B.J. An implementation of new and dispose using boundary tags. Pascal News 19 (Sept. 1980), 49-59.Google ScholarGoogle Scholar
  9. 9 HrXT, J.B. A storage management laboratory. Aust. Comput. Sci. Commun. 2, 1 (Jan. 1980), 185-193.Google ScholarGoogle Scholar
  10. 10 KAUFMAN, A. Tailored-list and recombination-delaying buddy systems. ACM Trans. Program. Lang. Syst. 6, 1 (Jan. 1984), 118-125. Google ScholarGoogle Scholar
  11. 11 KNOWLTON, K.C. A fast storage allocator. Commun. ACM 8, 10 (Oct. 1965), 623-625. Google ScholarGoogle Scholar
  12. 12 KNUTH, D. E. The Art of Computer Programming. Vol. 1: Fundamental Algorithms. (2nd edition). Addison-Wesley, Reading, Mass., 1973, Sect. 2.5. Google ScholarGoogle Scholar
  13. 13 KNUTH, D. E. The Art of Computer Programming. Vol. 3: Sorting and Searching. Addison- Wesley, Reading, Mass., 1973. Google ScholarGoogle Scholar
  14. 14 PETERSON, J. L., AND NORMAN, T. A. Buddy systems. Commun. ACM 20, 6 (June 1977), 421-431. Google ScholarGoogle Scholar
  15. 15 ROBSON, J.M. Worst case fragmentation of first fit and best fit storage allocation strategies. Comput. J. 20, 3 (Aug. 1977), 242-244.Google ScholarGoogle Scholar
  16. 16 SHORE, J.E. On the external storage fragmentation produced by first-fit and best-fit allocation strategies. Commun. ACM 18, 8 (Aug. 1975), 433-440. Google ScholarGoogle Scholar
  17. 17 SHORE, J. E~ Anomalous behavior of the fifty-percent rule in dynamic memory allocation. Commun. ACM 20, 11 (Nov. 1977), 812-820. Google ScholarGoogle Scholar
  18. 18 STEPHENSON, C.J. Fast fits--New methods for dynamic storage allocation. In Proceedings of the 9th Symposium on Operating System Principles (Bretton Woods, N.H., Oct. 11-13, 1983). ACM, New York, 1983, pp. 30-32. Google ScholarGoogle Scholar
  19. 19 VUILLEMIN, J. A unifying look at data structures. Commun. ACM 23, 4 (Apr. 1980), 229-239. Google ScholarGoogle Scholar

Index Terms

  1. Efficient implementation of the first-fit strategy for dynamic storage allocation

Recommendations

Reviews

Gerald David Chandler

This paper describes the many types of dynamic memory allocation strategies and discusses the many possible implementation algorithms for each. Perhaps the most commonly used strategy is first-fit, in which a list is maintained of the memory blocks that can be allocated; the block allocated in response to a request is the first on the list that is large enough to satisfy the request. Before 1968, the usual algorithm used to implement first-fit used a linked list to maintain the list of free blocks; subsequently, many alternatives have appeared. Brent presents an algorithm that divides the free space into fixed size segments; within a segment, blocks are linked in the standard manner. The novel aspect of his approach is to maintain an index to the segments that contains the largest block starting in each segment. The index itself makes use of the same data structure that heap sort is based on—an array representing a binary tree in which the descendants of node N are in array elements 2 N and 2 N + 1. Through the use of this index, the time for allocating or disposing of an element is reduced from O( B) to O(log B) where B is the number of active blocks. A simulation-based comparison of the indexed approach with the standard linked algorithm indicates that the new algorithm is faster for B greater than 100. An appendix contains the complete Pascal code that implements the algorithm. Because this program is clearly written, a separate, earlier presentation of pseudocode appears to be unnecessary. As with the programs, the paper itself is clear and well organized. It is worth reading. As a last thought, I wonder why the editors of the journal printed this paper a long four years after it was accepted, while the paper on page 345 in the same issue appears only five months after acceptance.

Access critical reviews of Computing literature here

Become a reviewer for Computing Reviews.

Comments

Login options

Check if you have access through your login credentials or your institution to get full access on this article.

Sign in

Full Access

  • Published in

    cover image ACM Transactions on Programming Languages and Systems
    ACM Transactions on Programming Languages and Systems  Volume 11, Issue 3
    July 1989
    137 pages
    ISSN:0164-0925
    EISSN:1558-4593
    DOI:10.1145/65979
    Issue’s Table of Contents

    Copyright © 1989 ACM

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    • Published: 1 July 1989
    Published in toplas Volume 11, Issue 3

    Permissions

    Request permissions about this article.

    Request Permissions

    Check for updates

    Qualifiers

    • article

PDF Format

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader