+
+/* Returns the number of bytes required to accomodate a bitmap
+ with BIT_CNT bits. */
+size_t
+bitmap_needed_bytes (size_t bit_cnt)
+{
+ struct bitmap b;
+ b.bit_cnt = bit_cnt;
+ return byte_cnt (&b) + sizeof b;
+}
+
+/* Creates and returns a bitmap with BIT_CNT bits in the
+ BLOCK_SIZE bytes of storage preallocated at BLOCK.
+ BLOCK_SIZE must be at least bitmap_needed_bytes(BIT_CNT). */
+struct bitmap *
+bitmap_create_preallocated (size_t bit_cnt, void *block, size_t block_size)
+{
+ struct bitmap *b = block;
+
+ ASSERT (block_size >= bitmap_needed_bytes (bit_cnt));
+
+ b->bit_cnt = bit_cnt;
+ b->bits = (elem_type *) (b + 1);
+ bitmap_set_all (b, false);
+ return b;
+}
+