[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ALLOC_IN_POOL, Re: lynx-dev lynx2.8.5dev.11
From: |
Leonid Pauzner |
Subject: |
Re: ALLOC_IN_POOL, Re: lynx-dev lynx2.8.5dev.11 |
Date: |
Tue, 3 Dec 2002 02:33:50 +0300 (MSK) |
1-Dec-2002 23:30 Bela Lubkin wrote:
> #define POOLallocHTLine(ptr, size) { HTStyleChange* _tmp_; \
>
> ALLOC_IN_POOL(HTMainText->pool,HTPool,\
> _round_(LINE_SIZE(size)), \
> _tmp_, \
> _align_); \
> ptr = (HTLine*)_tmp_; \
> }
> The expansion is appalling, makes me think something here should be a
> function rather than a macro (word-wrapped by me):
> { HTStyleChange * _tmp_ ; if (! HTMainText->pool) { _tmp_ = 0 ; } else {
> if ((sizeof (void *) / sizeof (HTStyleChange))) HTMainText->pool->used
> += (HTMainText->pool->used % (sizeof (void *) / sizeof (HTStyleChange)))
> ; if ((8192 - 4 * sizeof (void *) - sizeof (struct _HTPool *) + sizeof
> (int)) / sizeof (HTStyleChange) - HTMainText->pool->used >= ((sizeof
> (HTLine) + (previous->size)) % sizeof (HTStyleChange) ? (sizeof
> (HTLine) + (previous->size)) / sizeof (HTStyleChange) + 1 : (sizeof
> (HTLine) + (previous->size)) / sizeof (HTStyleChange))) { _tmp_ =
> HTMainText->pool->data + HTMainText->pool->used ; HTMainText->pool->used
> += ((sizeof (HTLine) + (previous->size)) % sizeof (HTStyleChange) ?
> (sizeof (HTLine) + (previous->size)) / sizeof (HTStyleChange) + 1
> : (sizeof (HTLine) + (previous->size)) / sizeof (HTStyleChange)) ;
> } else { HTPool * newpool = (HTPool *) LY_check_calloc (1 , sizeof
> (HTPool)) ; if (! newpool) { _tmp_ = 0 ; } else { newpool->prev =
> HTMainText->pool ; newpool->used = ((sizeof (HTLine) + (previous->size))
> % sizeof (HTStyleChange) ? (sizeof (HTLine) + (previous->size)) / sizeof
> (HTStyleChange) + 1 : (sizeof (HTLine) + (previous->size)) / sizeof
> (HTStyleChange)) ; _tmp_ = newpool->data ; HTMainText->pool = newpool ;
> } } } ; temp = (HTLine *) _tmp_ ; } ;
> The warning comes from this portion of it:
> += (HTMainText->pool->used % (sizeof (void *) / sizeof (HTStyleChange)))
> sizeof(void *) on this machine is 4; sizeof(HTStyleChange) is 8.
The proposed patch, inspired by Bela Lubkin:
pack HTStyleChange bitfiels;
remove "alignment" issue completely;
use a constant to avoid multiple macro expansions (above).
--- gridtext.ori Mon Dec 2 02:07:38 2002
+++ gridtext.c Tue Dec 3 02:17:00 2002
@@ -149,16 +149,12 @@ PUBLIC int LYsb_begin = -1;
PUBLIC int LYsb_end = -1;
#endif
-#ifndef CHAR_BIT
-#define CHAR_BIT 8
-#endif
- /*try to fit in 2 shorts*/
+ /*try to fit in 32bit */
typedef struct {
- unsigned int direction:2; /* on or off */
- unsigned int horizpos: (sizeof(short)*CHAR_BIT-2);
- /* horizontal position of this change */
- unsigned short style; /* which style to change to */
+ unsigned int direction:2; /* on or off */
+ unsigned int horizpos:14; /* horizontal position of this change */
+ unsigned int style:16; /* which style to change to */
} HTStyleChange;
#if defined(USE_COLOR_STYLE)
@@ -167,7 +163,7 @@ typedef struct {
static HTStyleChange stylechanges_buffers[2][MAX_STYLES_ON_LINE];
#endif
-#define POOL_SIZE (8192 - 4*sizeof(void*) - sizeof(struct _HTPool*) +
sizeof(int)) / sizeof(HTStyleChange)
+enum { POOL_SIZE = (8192 - 4*sizeof(void*) - sizeof(struct _HTPool*) +
sizeof(int)) / sizeof(HTStyleChange) };
typedef struct _HTPool {
HTStyleChange data[POOL_SIZE];
@@ -205,7 +201,7 @@ pool provided their length will never ex
to be very efficient.
[Several types of memory-hungry objects are stored in the pool now: styles,
lines, anchors, and FormInfo. Arrays of HTStyleChange are stored as is,
-other objects are aligned to sizeof(void*) bytes and stored using a cast.]
+other objects are stored using a cast.]
Pool are referenced by pointer to the chunk that contains free slots. Macros
that allocate memory in pools update that pointer if needed.
@@ -214,7 +210,7 @@ ALLOC_IN_POOL.
Here is a description of those macros as C++ functions (with names mentioned
above and with use of C++ references)
-void ALLOC_IN_POOL( P*& pool, pool_type, int toalloc, T*& ptr, int align=1)
+void ALLOC_IN_POOL( P*& pool, pool_type, int toalloc, T*& ptr)
- allocates 'toalloc' items in the pool of type 'pool_type' pointed by
'pool', sets the pointer 'ptr' to the "allocated" memory and updates 'pool'
if necessary. Sets 'ptr' to NULL if fails.
@@ -230,17 +226,15 @@ void POOL_FREE( pool_type , P*& ptr)
*************************************************************************/
/*
- * void ALLOC_IN_POOL( P*& pool, pool_type, int toalloc, T*& ptr, int align=1)
+ * void ALLOC_IN_POOL( P*& pool, pool_type, int toalloc, T*& ptr)
* - allocates 'toalloc' items in the pool of type 'pool_type' pointed by
* 'pool', sets the pointer 'ptr' to the "allocated" memory and updates
* 'pool' if necessary. Sets 'ptr' to NULL if fails.
*/
-#define ALLOC_IN_POOL(pool,pool_type,toalloc,ptr,align) \
+#define ALLOC_IN_POOL(pool,pool_type,toalloc,ptr) \
if (!pool) { \
ptr = NULL; \
} else { \
- if (align) \
- pool->used += (pool->used % align); \
if (POOL_SIZE - pool->used >= toalloc) { \
ptr = pool->data + pool->used; \
pool->used += toalloc; \
@@ -286,27 +280,25 @@ void POOL_FREE( pool_type , P*& ptr)
}
/**************************************************************************/
-#define _sz_ sizeof(HTStyleChange) /* 4 */
-#define _align_ (sizeof(void*)/_sz_) /*64bit OS!*/
-#define _round_(x) (x%_sz_ ? x/_sz_ + 1: x/_sz_)
+#define _sz_ sizeof(HTStyleChange) /* 4 */
+#define _round_up_(x) (x%_sz_ ? x/_sz_ + 1: x/_sz_)
#define POOLallocstyles(ptr, N) ALLOC_IN_POOL(HTMainText->pool,HTPool,\
N, \
- ptr, \
- 1)
+ ptr)
#define POOLallocHTLine(ptr, size) { HTStyleChange* _tmp_; \
+ int N = _round_up_(LINE_SIZE(size)); \
ALLOC_IN_POOL(HTMainText->pool,HTPool,\
- _round_(LINE_SIZE(size)), \
- _tmp_, \
- _align_); \
- ptr = (HTLine*)_tmp_; \
+ N, \
+ _tmp_); \
+ ptr = (HTLine*)_tmp_; \
}
#define POOLtypecalloc(T,ptr) { HTStyleChange* _tmp_; \
+ int N = _round_up_(sizeof(T)); \
ALLOC_IN_POOL(HTMainText->pool,HTPool,\
- _round_(sizeof(T)), \
- _tmp_, \
- _align_); \
- ptr = (T*)_tmp_; \
+ N, \
+ _tmp_); \
+ ptr = (T*)_tmp_; \
}
typedef struct _line {
; To UNSUBSCRIBE: Send "unsubscribe lynx-dev" to address@hidden
- Re: ALLOC_IN_POOL, Re: lynx-dev lynx2.8.5dev.11, (continued)
- Re: ALLOC_IN_POOL, Re: lynx-dev lynx2.8.5dev.11, Leonid Pauzner, 2002/12/03
- Re: ALLOC_IN_POOL, Re: lynx-dev lynx2.8.5dev.11, Bela Lubkin, 2002/12/04
- Re: ALLOC_IN_POOL, Re: lynx-dev lynx2.8.5dev.11, Leonid Pauzner, 2002/12/04
- Re: ALLOC_IN_POOL, Re: lynx-dev lynx2.8.5dev.11, Leonid Pauzner, 2002/12/04
- Re: ALLOC_IN_POOL, Re: lynx-dev lynx2.8.5dev.11, Leonid Pauzner, 2002/12/04
Re: ALLOC_IN_POOL, Re: lynx-dev lynx2.8.5dev.11, Thomas E. Dickey, 2002/12/02
Re: ALLOC_IN_POOL, Re: lynx-dev lynx2.8.5dev.11,
Leonid Pauzner <=
Re: lynx-dev lynx2.8.5dev.11, pg, 2002/12/02
Re: lynx-dev lynx2.8.5dev.11, Webmaster Jim, 2002/12/03
Re: lynx-dev lynx2.8.5dev.11, Leonid Pauzner, 2002/12/08
Re: lynx-dev lynx2.8.5dev.11, Henry Nelson, 2002/12/02