File indexing completed on 2024-04-21 14:57:50

0001 /*
0002  * Copyright (C) 2002 Apple Computer, Inc.
0003  * Copyright (C) 2003 Dirk Mueller (mueller@kde.org)
0004  *
0005  * Portions are Copyright (C) 1998 Netscape Communications Corporation.
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Lesser General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2.1 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public
0018  * License along with this library; if not, write to the Free Software
0019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0020  *
0021  * Alternatively, the contents of this file may be used under the terms
0022  * of either the Mozilla Public License Version 1.1, found at
0023  * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
0024  * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
0025  * (the "GPL"), in which case the provisions of the MPL or the GPL are
0026  * applicable instead of those above.  If you wish to allow use of your
0027  * version of this file only under the terms of one of those two
0028  * licenses (the MPL or the GPL) and not to allow others to use your
0029  * version of this file under the LGPL, indicate your decision by
0030  * deletingthe provisions above and replace them with the notice and
0031  * other provisions required by the MPL or the GPL, as the case may be.
0032  * If you do not delete the provisions above, a recipient may use your
0033  * version of this file under any of the LGPL, the MPL or the GPL.
0034  */
0035 
0036 #ifndef RENDERARENA_H
0037 #define RENDERARENA_H
0038 
0039 #define KHTML_USE_ARENA_ALLOCATOR
0040 
0041 #include "misc/arena.h"
0042 #include "misc/shared.h"
0043 
0044 #include <stdlib.h>
0045 
0046 namespace khtml
0047 {
0048 
0049 #define KHTML_MAX_RECYCLED_SIZE 400
0050 #define KHTML_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y))
0051 
0052 class RenderArena: public Shared<RenderArena>
0053 {
0054 public:
0055     RenderArena(unsigned int arenaSize = 4096);
0056     ~RenderArena();
0057 
0058     // Memory management functions
0059     void *allocate(size_t size);
0060     void  free(size_t size, void *ptr);
0061 
0062 private:
0063     // Underlying arena pool
0064     ArenaPool m_pool;
0065 
0066     // The recycler array is sparse with the indices being multiples of 4,
0067     // i.e., 0, 4, 8, 12, 16, 20, ...
0068     void *m_recyclers[KHTML_MAX_RECYCLED_SIZE >> 2];
0069 };
0070 
0071 } // namespace
0072 
0073 #endif
0074