Changeset 1314 for cpp/frams/util/list.h


Ignore:
Timestamp:
07/11/24 17:22:23 (10 months ago)
Author:
Maciej Komosinski
Message:

Added realloc() implementation that behaves like free() when size==0 - consistently on all platforms, in contrast to standard realloc()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified cpp/frams/util/list.h

    r793 r1314  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2024  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    99#include <string.h>
    1010#include <common/nonstd.h>
     11#include <common/realloc-free0size.h>
    1112
    1213//#define SLISTSTATS
     
    4445                if (mem || x)
    4546                {
    46                         mem = (T*)realloc(mem, x*sizeof(T));
     47                        mem = (T*)realloc_free0size(mem, x*sizeof(T));
    4748#ifdef SLISTSTATS
    4849                        SListStats::stats.allocations++;
    4950                        SListStats::stats.copied += sizeof(T)*min(x, have);
    50 #endif 
     51#endif
    5152                }
    5253                have = x;
     
    150151        {
    151152                setSize(src.size());
    152                 memcpy(mem, src.mem, src.size()*sizeof(T));
     153                if (mem != NULL)
     154                        memcpy(mem, src.mem, src.size()*sizeof(T));
    153155        }
    154156        void operator+=(const SListTempl<T>&src) ///< append src contents
Note: See TracChangeset for help on using the changeset viewer.