类的构造函数 类型一样 变量名不一样无所谓

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// 你必须定义一个 `main()` 函数入口。
#include <iostream>
using namespace std;
#include <string.h>
typedef const char* FX_LPCSTR;
typedef char FX_CHAR;
typedef int FX_STRSIZE;
typedef int FX_BOOL;
typedef unsigned char FX_BYTE;
  
#define FX_Alloc(type, size)                        (type*)calloc(size, sizeof(type))
#define FX_Free(ptr)                                free(ptr)
struct CFX_StringData {
    long        m_nRefs;
    FX_STRSIZE  m_nDataLength;
    FX_STRSIZE  m_nAllocLength;
    FX_CHAR     m_String[1];
};
static CFX_StringData* FX_AllocString(int nLen)
{
    // |nLen| is currently declared as in |int|. TODO(palmer): It should be
    // a |size_t|, or at least unsigned.
 if (nLen == 0 || nLen < 0) {
        return NULL;
    }
    int nSize = nLen;
    nSize += sizeof(long) * 3 + 1;
    CFX_StringData* pData = (CFX_StringData*)FX_Alloc(FX_BYTE, nSize);
    if (!pData) {
        return NULL;
    }
    pData->m_nAllocLength = nLen;
    pData->m_nDataLength = nLen;
    pData->m_nRefs = 1;
    pData->m_String[nLen] = 0;
    return pData;
}
 static void FX_ReleaseString(CFX_StringData* pData)
{
    if (pData == NULL) {
        return;
    }
    pData->m_nRefs --;
    if (pData->m_nRefs <= 0) {
        FX_Free(pData);
    }
}
 
 
 
 
class CFX_Object
{
  public:
  void* operator new(size_t size, FX_LPCSTR file, int line)
  {
    return malloc(size);
  }
    
  void operator delete(void*p,FX_LPCSTR file,int size)
  {
    free(p);
  }
  void* operator new(size_t size)
  {
    return malloc(size);
  }
  void operator delete(void* p)
  {
    free(p);
  }
    void*           operator new[] (size_t size, FX_LPCSTR file, int line)
    {
        return malloc(size);
    }
    void            operator delete[] (void* p, FX_LPCSTR file, int line)
    {
        free(p);
    }
    void*           operator new[] (size_t size)
    {
        return malloc(size);
    }
    void            operator delete[] (void* p)
    {
        free(p);
    }
    void*           operator new (size_t, void* buf)
    {
        return buf;
    }
    void            operator delete (void*, void*)                          {}
};
  
  
class CFX_ByteString : public CFX_Object
{
public:
   CFX_ByteString(FX_LPCSTR ptr, FX_STRSIZE len = -1);
protected:
    struct CFX_StringData*  m_pData;
    void                    AllocCopy(CFX_ByteString& dest, FX_STRSIZE nCopyLen, FX_STRSIZE nCopyIndex) const;
};
  
CFX_ByteString::CFX_ByteString(FX_LPCSTR lpsz, FX_STRSIZE nLen)
{
    if (nLen < 0) {
        nLen = lpsz ? (FX_STRSIZE)strlen(lpsz) : 0;
    }
    if (nLen) {
        m_pData = FX_AllocString(nLen);
        if (m_pData) {
            memcpy(m_pData->m_String, lpsz, nLen);
        }
    } else {
        m_pData = NULL;
    }
}
  
 
void CFX_ByteString::AllocCopy(CFX_ByteString& dest, FX_STRSIZE nCopyLen, FX_STRSIZE nCopyIndex) const
{
  return;
}
 
int main()
{
  
  cout << sizeof(CFX_StringData) << endl;
  return 0;
}
  
        

  

posted on   lydstory  阅读(23)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2019-12-30 pdf 英文标准
2019-12-30 pdf to unicode
2019-12-30 xrandr
2019-12-30 pdf head
2019-12-30 pdf 文档
2019-12-30 pdf load
2019-12-30 1个pc 多个-l 多个-l

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示