/[LeafOK_CVS]/lbbs/src/memory_pool.c
ViewVC logotype

Diff of /lbbs/src/memory_pool.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.3 by sysadm, Sat Jun 14 02:02:54 2025 UTC Revision 1.6 by sysadm, Sat Oct 18 12:06:10 2025 UTC
# Line 14  Line 14 
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
 #include "memory_pool.h"  
17  #include "log.h"  #include "log.h"
18    #include "memory_pool.h"
19  #include <stdlib.h>  #include <stdlib.h>
20  #include <string.h>  #include <string.h>
21    
# Line 98  inline static void *memory_pool_add_chun Line 98  inline static void *memory_pool_add_chun
98          }          }
99    
100          p_node = p_pool->p_free;          p_node = p_pool->p_free;
101          memcpy(p_chunk + (p_pool->node_count_per_chunk - 1) * p_pool->node_size, &p_node, sizeof(p_node));          memcpy((char *)p_chunk + (p_pool->node_count_per_chunk - 1) * p_pool->node_size, &p_node, sizeof(p_node));
102          for (i = 0; i < p_pool->node_count_per_chunk - 1; i++)          for (i = 0; i < p_pool->node_count_per_chunk - 1; i++)
103          {          {
104                  p_node = p_chunk + (i + 1) * p_pool->node_size;                  p_node = (char *)p_chunk + (i + 1) * p_pool->node_size;
105                  memcpy(p_chunk + i * p_pool->node_size, &p_node, sizeof(p_node));                  memcpy((char *)p_chunk + i * p_pool->node_size, &p_node, sizeof(p_node));
106          }          }
107    
108          p_pool->p_chunks[p_pool->chunk_count] = p_chunk;          p_pool->p_chunks[p_pool->chunk_count] = p_chunk;
# Line 149  void memory_pool_free(MEMORY_POOL *p_poo Line 149  void memory_pool_free(MEMORY_POOL *p_poo
149          }          }
150    
151          // For test and debug          // For test and debug
152          // memory_pool_check_node(p_pool, p_node);  #ifdef _DEBUG
153            memory_pool_check_node(p_pool, p_node);
154    #endif
155    
156          memcpy(p_node, &(p_pool->p_free), sizeof(p_pool->p_free));          memcpy(p_node, &(p_pool->p_free), sizeof(p_pool->p_free));
157          p_pool->p_free = p_node;          p_pool->p_free = p_node;
# Line 173  int memory_pool_check_node(MEMORY_POOL * Line 175  int memory_pool_check_node(MEMORY_POOL *
175    
176          for (i = 0; i < p_pool->chunk_count; i++)          for (i = 0; i < p_pool->chunk_count; i++)
177          {          {
178                  if (p_node >= p_pool->p_chunks[i] && p_node < p_pool->p_chunks[i] + chunk_size)                  if (p_node >= p_pool->p_chunks[i] && (char *)p_node < (char *)(p_pool->p_chunks[i]) + chunk_size)
179                  {                  {
180                          if ((size_t)(p_node - p_pool->p_chunks[i]) % p_pool->node_size == 0)                          if ((size_t)((char *)p_node - (char *)(p_pool->p_chunks[i])) % p_pool->node_size == 0)
181                          {                          {
182                                  return 0; // OK                                  return 0; // OK
183                          }                          }
184                          else                          else
185                          {                          {
186                                  log_error("Address of node (%p) is not aligned with border of chunk %d [%p, %p)\n",                                  log_error("Address of node (%p) is not aligned with border of chunk %d [%p, %p)\n",
187                                                    i, p_node >= p_pool->p_chunks[i], p_pool->p_chunks[i] + chunk_size);                                                    i, p_node >= p_pool->p_chunks[i], (char *)(p_pool->p_chunks[i]) + chunk_size);
188                                  return -3;                                  return -3;
189                          }                          }
190                  }                  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1