Skip to content

Commit

Permalink
libdeng: Moved BlockSet to libdeng (as memoryblockset.c/h)
Browse files Browse the repository at this point in the history
Made the file name more specific to avoid overloading the name Block
(as in de::Block) with a new meaning.
  • Loading branch information
skyjake committed Nov 14, 2012
1 parent c683bb1 commit 83ee0d5
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 156 deletions.
2 changes: 0 additions & 2 deletions doomsday/engine/engine.pro
Expand Up @@ -135,7 +135,6 @@ DENG_HEADERS += \
include/audio/sys_audio.h \
include/audio/sys_audiod_dummy.h \
include/binarytree.h \
include/blockset.h \
include/busymode.h \
include/cbuffer.h \
include/client/cl_def.h \
Expand Down Expand Up @@ -438,7 +437,6 @@ SOURCES += \
src/audio/s_wav.c \
src/audio/sys_audiod_dummy.c \
src/binarytree.cpp \
src/blockset.c \
src/busymode.cpp \
src/cbuffer.c \
src/client/cl_frame.c \
Expand Down
97 changes: 0 additions & 97 deletions doomsday/engine/include/blockset.h

This file was deleted.

3 changes: 2 additions & 1 deletion doomsday/engine/src/con_data.cpp
Expand Up @@ -33,9 +33,10 @@

#include "cbuffer.h"
#include "m_misc.h"
#include "blockset.h"
#include "pathtree.h"

#include <de/memoryblockset.h>

// Substrings in CVar names are delimited by this character.
#define CVARDIRECTORY_DELIMITER '-'

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/filehandle.cpp
Expand Up @@ -31,10 +31,10 @@
#include "de_console.h"
#include "de_filesys.h"

#include "blockset.h"
#include "filehandle.h"

#include <de/memory.h>
#include <de/memoryblockset.h>
#include <de/NativePath>

namespace de {
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/src/r_things.c
Expand Up @@ -52,13 +52,13 @@
#include "de_misc.h"

#include "def_main.h"

#include "blockset.h"
#include "m_stack.h"
#include "texture.h"
#include "texturevariant.h"
#include "materialvariant.h"

#include <de/memoryblockset.h>

// MACROS ------------------------------------------------------------------

#define MAX_FRAMES (128)
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/src/resource/materials.cpp
Expand Up @@ -31,14 +31,15 @@
#include "de_misc.h"
#include "de_audio.h" // For texture, environmental audio properties.

#include "blockset.h"
#include "texture.h"
#include "texturevariant.h"
#include "materialvariant.h"
#include "pathtree.h"

#include <de/Error>
#include <de/Log>
#include <de/memory.h>
#include <de/memoryblockset.h>
#include <de/memoryzone.h>

/// Number of materials to block-allocate.
Expand Down
100 changes: 100 additions & 0 deletions doomsday/libdeng/include/de/memoryblockset.h
@@ -0,0 +1,100 @@
/**
* @file memoryblockset.h
* Set of memory blocks allocated from the zone. @ingroup system
*
* @authors Copyright © 2006-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2012 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_MEMORY_BLOCKSET_H
#define LIBDENG_MEMORY_BLOCKSET_H

#include "libdeng.h"

#ifdef __cplusplus
extern "C" {
#endif

struct blockset_block_s;

/**
* Block memory batch allocator.
*
* These are used instead of many calls to M_Malloc() when the number of
* required elements is unknown and when linear allocation would be too
* slow.
*
* Memory is allocated as needed in blocks of "batchSize" elements. When
* a new element is required we simply reserve a ptr in the previously
* allocated block of elements or create a new block just in time.
*
* The internal state of a blockset is managed automatically.
*/
typedef struct blockset_s {
/// Number of elements to allocate in each block.
size_t _elementsPerBlock;

/// Running total of the number of used elements across all blocks.
size_t _elementsInUse;

/// sizeof an individual element in the set.
size_t _elementSize;

/// Number of blocks in the set.
size_t _blockCount;

/// Vector of blocks in the set.
struct blockset_block_s* _blocks;
} blockset_t;

/**
* Creates a new block memory allocator.
*
* @param sizeOfElement Required size of each element in bytes. Must be at
* least 1 (bytes).
* @param batchSize Number of elements in each block of the set. Must
* be at least 1.
*
* @return Ptr to the newly created blockset.
*/
DENG_PUBLIC blockset_t* BlockSet_New(size_t sizeOfElement, size_t batchSize);

/**
* Free an entire blockset. All memory allocated is released for all elements
* in all blocks and any used for the blockset itself.
*
* @param set The blockset to be freed.
*/
DENG_PUBLIC void BlockSet_Delete(blockset_t* set);

/**
* Return a ptr to the next unused element in the blockset.
*
* @param set The blockset to return the next element from.
*
* @return Ptr to the next unused element in the blockset.
*/
DENG_PUBLIC void* BlockSet_Allocate(blockset_t* set);

/// @return Total number of elements from the set that are currently in use.
DENG_PUBLIC size_t BlockSet_Count(blockset_t* set);

#ifdef __cplusplus
} // extern "C"
#endif

#endif /* LIBDENG_BLOCKSET_H */
4 changes: 3 additions & 1 deletion doomsday/libdeng/libdeng.pro
Expand Up @@ -61,6 +61,7 @@ HEADERS += \
include/de/garbage.h \
include/de/libdeng.h \
include/de/memory.h \
include/de/memoryblockset.h \
include/de/memoryzone.h \
include/de/point.h \
include/de/reader.h \
Expand All @@ -82,6 +83,7 @@ SOURCES += \
src/garbage.cpp \
src/libdeng.c \
src/memory.c \
src/memoryblockset.c \
src/memoryzone.c \
src/memoryzone_private.h \
src/point.c \
Expand All @@ -92,7 +94,7 @@ SOURCES += \
src/str.c \
src/stringarray.cpp \
src/timer.cpp \
src/writer.c
src/writer.c \

# Installation ---------------------------------------------------------------

Expand Down

0 comments on commit 83ee0d5

Please sign in to comment.