From: short <> Date: Tue, 4 Nov 2003 06:41:35 +0000 (+0000) Subject: captive_shared_cache_map_object_FileSizes_changed(): Improved performance. X-Git-Tag: captive-1_0_2~34 X-Git-Url: http://git.jankratochvil.net/?p=captive.git;a=commitdiff_plain;h=000196808efeead1b2aee0c3aaa0ef64c11ef335 captive_shared_cache_map_object_FileSizes_changed(): Improved performance. - Prevent continous reallocation to (n+1) size, we use now (n*2) sizes for logaritmic time complexity. --- diff --git a/src/libcaptive/cc/sharedcachemap-priv.h b/src/libcaptive/cc/sharedcachemap-priv.h index 1b353e8..af2fcac 100644 --- a/src/libcaptive/cc/sharedcachemap-priv.h +++ b/src/libcaptive/cc/sharedcachemap-priv.h @@ -54,11 +54,17 @@ struct _CaptiveSharedCacheMapObject { * as the offsets are usually PAGE_SIZE aligned due to pin-Bcb expectations. */ guint64 FileSize; /* ==CC_FILE_SIZES.FileSize.QuadPart */ - /* We use 'FileSize' instead of 'ValidDataLength' as I assume W32 + /* We use do not use 'ValidDataLength' as I assume W32 * automatically increases 'ValidDataLength' during Cache Manager write operations. * We do not increase it and therefore it is mostly useless for us. */ guint64 ValidDataLength; /* ==CC_FILE_SIZES.ValidDataLength.QuadPart */ + /* The real allocation size of 'buffer' and 'pages'. + * Maintained by captive_shared_cache_map_object_FileSizes_changed() + * to prevent continous reallocation to (n+1) size. + * We use (n*2) sizes for logaritmic time complexity. + */ + guint64 alloc_length; CACHE_MANAGER_CALLBACKS CallBacks; VOID *LazyWriterContext; gboolean PinAccess; diff --git a/src/libcaptive/cc/sharedcachemap.c b/src/libcaptive/cc/sharedcachemap.c index 28d2267..9ee7cd4 100644 --- a/src/libcaptive/cc/sharedcachemap.c +++ b/src/libcaptive/cc/sharedcachemap.c @@ -183,8 +183,6 @@ size_new_big: } if (size_old!=size_new) { -gpointer buffer_new; - /* ntfs.sys of NT-5.1sp1 may extend StreamFileObject while dirty pins exist. * How to extend SharedCacheMap size without changing the memory location? * I hope ntfs.sys does not expect long-term absolute position of its @@ -195,8 +193,17 @@ gpointer buffer_new; g_assert(!captive_shared_cache_map_object->map); g_assert(!g_hash_table_size(captive_shared_cache_map_object->pin_hash)); } + } + + if (size_new > captive_shared_cache_map_object->alloc_length) { +gpointer buffer_new; + + size_new*=2; + size64_new*=2; + if (size_new!=size64_new) + goto size_new_big; - if (AllocationSize) { + if (size_new) { gpointer base; int errint; @@ -226,10 +233,10 @@ int errint; memcpy(buffer_new,captive_shared_cache_map_object->buffer, MIN(AllocationSize,captive_shared_cache_map_object->AllocationSize)); - if (captive_shared_cache_map_object->AllocationSize) { + if (captive_shared_cache_map_object->alloc_length) { int errint; - errint=munmap(captive_shared_cache_map_object->buffer,size_old); + errint=munmap(captive_shared_cache_map_object->buffer,captive_shared_cache_map_object->alloc_length); g_assert(errint==0); } @@ -246,11 +253,14 @@ guint64 now; } } #endif + captive_shared_cache_map_object->pages=g_realloc(captive_shared_cache_map_object->pages, size_new/PAGE_SIZE*sizeof(*captive_shared_cache_map_object->pages)); if (size_new>size_old) /* prevent 'size_new-size_old' as it is unsigned! */ memset(captive_shared_cache_map_object->pages+(size_old/PAGE_SIZE),0, (size_new-size_old)/PAGE_SIZE*sizeof(*captive_shared_cache_map_object->pages)); + + captive_shared_cache_map_object->alloc_length=size_new; } captive_shared_cache_map_object->AllocationSize=AllocationSize;