Почему класс берёт на 8 байтов памяти больше?

У меня есть класс A. В нём есть только 10 методов и куча перегрузок операторов. А также другой класс, пусть его название будет B, он хранит в себе указатель на динамический массив. B класс весит 8 байтов и это размер указателя, что логично. (Всё проверял через sizeof()), но почему-то класс A весит целых 16 байтов, хотя ничего кроме B класса в нём нету. Как и почему??

#pragma once
#include <iostream>
#include <Algorithm>
#include <regex>
#include <string>
#include <vector>
#include <malloc.h>
#pragma warning(disable : 6386)

using namespace std;

//*==| BLOODYSTRING |==*

class BloodyString;
class CoreBloodyString;

#define THE_BLOODY_STRING
#define THE_BCOR

#ifdef BSTR_STANDART_INDEX
#define BSTANDART 1
#else
#define BSTANDART 0
#endif

#ifdef OFF_BLOODY_STRING
#define OFF_BSTR
#undef THE_BLOODY_STRING
#undef THE_BCOR
#undef BSTANDART
#endif

#ifndef OFF_BSTR
using bstr = BloodyString;
using bstring = BloodyString;
#endif

#ifdef THE_BCOR
class CoreBloodyString
{
public:

    #define BCOR_INVALID_ARG 829521443
    #define BCOR_HEAP_ERROR 891948975

    char* linkbuffer = (char*)malloc(0);
    
    void setsize(size_t newsize);
    void setval(char* val, size_t sizeval);
    void addval(char* val, size_t sizeval);
    void push(char val);
    void deldata();

    ~CoreBloodyString();
};

CoreBloodyString::~CoreBloodyString()
{
    free(linkbuffer);
}

void CoreBloodyString::setsize(size_t newsize)
{
    char* newlink = (char*)malloc(sizeof(char) * newsize);
    if (newlink == nullptr)
    {
        throw BCOR_HEAP_ERROR;
    }

    if (newsize == 0)
    {
        free(linkbuffer);
        linkbuffer = newlink;
        return;
    }
    size_t resmsize = _msize(linkbuffer);
    if (newsize < resmsize)
    {
        size_t corupdata = resmsize - newsize;
        resmsize = resmsize - corupdata;
    }

    if (resmsize == 0)
    {
        free(linkbuffer);
        linkbuffer = newlink;
        return;
    }

    for (size_t x = 0; x < resmsize; x++)
    {
        newlink[x] = linkbuffer[x];
    }

    free(linkbuffer);
    linkbuffer = newlink;
    return;
}

void CoreBloodyString::deldata()
{
    setsize(0);
}

void CoreBloodyString::setval(char* val, size_t sizeval)
{
    deldata();
    if (sizeval == 0)
    {
        return;
    }
    setsize(sizeval);
    for (size_t x = 0; x < sizeval; x++)
    {
        linkbuffer[x] = val[x];
    }
    return;
}

void CoreBloodyString::addval(char* val, size_t sizeval)
{
    if (sizeval == 0)
    {
        return;
    }
    const size_t sizelinkbuf = _msize(linkbuffer);
    const size_t tmpval = sizelinkbuf + sizeval;

    char* newlink = (char*)malloc(sizeof(char) * tmpval);
    if (newlink == nullptr)
    {
        throw BCOR_HEAP_ERROR;
    }
    for (size_t x = 0; x < sizelinkbuf; x++)
    {
        newlink[x] = linkbuffer[x];
    }
    free(linkbuffer);
    size_t tindex = sizelinkbuf;
    for (size_t x = 0; x < sizeval; x++)
    {
        newlink[tindex] = val[x];
        tindex++;
    }
    linkbuffer = newlink;
    return;
}

void CoreBloodyString::push(char val)
{
    const size_t newsize = _msize(linkbuffer) + 1;
    setsize(newsize);
    linkbuffer[newsize - 1] = val;
}
#endif

#ifdef THE_BLOODY_STRING
#define fbstr BloodyString

// *-----|Errors|-----*
#define BSTR_INVALID_ARG 9853452
#define BSTR_INVALID_DATA 8732452
#define BSTR_ERROR_IN_CORE 854359123
#define BSTR_MODULES_ERROR 8743758154

class BloodyString
{
private:
    void delnullter()
    {
        size_t sizenotnullter = _msize(core.linkbuffer);
        const size_t tmpsize = sizenotnullter;
        for (size_t x = 0; x < tmpsize; x++)
        {
            if (core.linkbuffer[x] == '\0')
            {
                sizenotnullter--;
            }
        }
        char* newdata = (char*)malloc(sizeof(char) * sizenotnullter);
        size_t tindex = 0;
        for (size_t x = 0; x < tmpsize; x++)
        {
            if (core.linkbuffer[x] != '\0')
            {
                newdata[tindex] = core.linkbuffer[x];
            }
            tindex++;
        }
        core.setval((char*)newdata, sizenotnullter);
        free(newdata);
    }
    CoreBloodyString core;
public:
    
    friend ostream& operator<< (ostream& out, BloodyString& mybstr);
    friend istream& operator>> (istream& in, BloodyString& mybstr);

    virtual void setbinstr(const char* str, size_t sizestr);
    virtual void pushbinstr(const char* str, size_t sizestr);
    virtual void setstr(const char* str);
    virtual void pushstr(const char* str);
    virtual void push(char sym);
    virtual size_t index(size_t val);
    virtual char* char_str();
    virtual const char* const_char_str();
    virtual string string_str();
    virtual size_t size();

    virtual BloodyString& operator<<(const char* str);
    virtual BloodyString& operator<<(char* str);
    virtual BloodyString& operator<<(string str);
    virtual BloodyString& operator<<(BloodyString str);
    virtual BloodyString& operator<<(long long str);
    virtual BloodyString& operator<<(char str);
    virtual BloodyString& operator<<(vector<char> str);

    virtual BloodyString& operator=(const char* str);
    virtual BloodyString& operator=(char* str);
    virtual BloodyString& operator=(string str);
    virtual BloodyString& operator=(BloodyString str);
    virtual BloodyString& operator=(long long str);
    virtual BloodyString& operator=(char str);
    virtual BloodyString& operator=(vector<char> str);

    BloodyString();
    BloodyString(const char* str);
    BloodyString(char* str);
    BloodyString(string str);
    BloodyString(BloodyString &str);
    BloodyString(long long str);
    BloodyString(char str);
    BloodyString(vector<char> str);

    virtual bool operator==(const char* str);
    virtual bool operator==(char* str);
    virtual bool operator==(string str);
    virtual bool operator==(BloodyString& str);
    virtual bool operator==(long long str);
    virtual bool operator==(char str);
    virtual bool operator==(vector<char> str);

    virtual bool operator!=(const char* str);
    virtual bool operator!=(char* str);
    virtual bool operator!=(string str);
    virtual bool operator!=(BloodyString& str);
    virtual bool operator!=(long long str);
    virtual bool operator!=(char str);
    virtual bool operator!=(vector<char> str);

    virtual char& operator[](size_t _index);
};

ostream& operator<< (ostream& out, BloodyString& mybstr)
{
    out << mybstr.core.linkbuffer;
    return out;
}

istream& operator>> (istream& in, BloodyString& mybstr)
{
    string tmp;
    getline(cin, tmp);
    mybstr.core.setval((char*)tmp.c_str(), tmp.length() + 1);
    return in;
}

char& BloodyString::operator[](size_t _index)
{
    if (this->size() - 1 < index(_index))
    {
        throw BSTR_INVALID_ARG;
    }
    return core.linkbuffer[index(_index)];
}

bool BloodyString::operator!=(const char* str)
{
    if (this->const_char_str() != str)
    {
        return true;
    }
    return false;
}

bool BloodyString::operator!=(char* str)
{
    if (this->char_str() != str)
    {
        return true;
    }
    return false;
}

bool BloodyString::operator!=(string str)
{
    if (this->const_char_str() != str.c_str())
    {
        return true;
    }
    return false;
}

bool BloodyString::operator!=(BloodyString& str)
{
    if (this->char_str() != str.char_str())
    {
        return true;
    }
    return false;
}

bool BloodyString::operator!=(long long str)
{
    if (this->string_str() != to_string(str))
    {
        return true;
    }
    return false;
}

bool BloodyString::operator!=(char str)
{
    if (this->size() == 0)
    {
        return true;
    }

    if (core.linkbuffer[0] != str)
    {
        return true;
    }
    return false;
}

bool BloodyString::operator!=(vector<char> str)
{
    string tmp(str.begin(), str.end());
    if (this->string_str() != tmp)
    {
        return true;
    }
    return false;
}

bool BloodyString::operator==(const char* str)
{
    if (this->const_char_str() == str)
    {
        return true;
    }
    return false;
}

bool BloodyString::operator==(char* str)
{
    if (this->char_str() == str)
    {
        return true;
    }
    return false;
}

bool BloodyString::operator==(string str)
{
    if (this->const_char_str() == str.c_str())
    {
        return true;
    }
    return false;
}

bool BloodyString::operator==(BloodyString& str)
{
    if (this->char_str() == str.char_str())
    {
        return true;
    }
    return false;
}

bool BloodyString::operator==(long long str)
{
    if (this->string_str() == to_string(str))
    {
        return true;
    }
    return false;
}

bool BloodyString::operator==(char str)
{
    if (this->size() == 0)
    {
        return false;
    }

    if (core.linkbuffer[0] == str)
    {
        return true;
    }
    return false;
}

bool BloodyString::operator==(vector<char> str)
{
    string tmp(str.begin(), str.end());
    if (this->string_str() == tmp)
    {
        return true;
    }
    return false;
}

BloodyString::BloodyString() {};

BloodyString::BloodyString(const char* str)
{
    core.setval((char*)str, strlen(str) + 1);
}

BloodyString::BloodyString(char* str)
{
    core.setval(str, strlen(str) + 1);
}

BloodyString::BloodyString(string str)
{
    core.setval((char*)str.c_str(), str.length() + 1);
}

BloodyString::BloodyString(BloodyString& str)
{
    core.setval(str.char_str(), str.size());
}

BloodyString::BloodyString(long long str)
{
    string strr = to_string(str);
    core.setval((char*)strr.c_str(), strr.length() + 1);
}

BloodyString::BloodyString(char str)
{
    core.setval((char*)str, 1);
}

BloodyString::BloodyString(vector<char> str)
{
    string tmp(str.begin(), str.end());
    core.setval((char*)tmp.c_str(), tmp.length() + 1);
}

BloodyString& BloodyString::operator=(const char* str)
{
    core.setval((char*)str, strlen(str) + 1);
    return *this;
}

BloodyString& BloodyString::operator=(char* str)
{
    core.setval(str, strlen(str) + 1);
    return *this;
}

BloodyString& BloodyString::operator=(string str)
{
    core.setval((char*)str.c_str(), str.length() + 1);
    return *this;
}

BloodyString& BloodyString::operator=(BloodyString str)
{
    core.setval(str.char_str(), str.size());
    return *this;
}

BloodyString& BloodyString::operator=(long long str)
{
    string tmp = to_string(str);
    core.setval((char*)tmp.c_str(), tmp.length() + 1);
    return *this;
}

BloodyString& BloodyString::operator=(char str)
{
    core.setval((char*)str, 1);
    return *this;
}

BloodyString& BloodyString::operator=(vector<char> str)
{
    string tmp(str.begin(), str.end());
    core.setval((char*)tmp.c_str(), tmp.length() + 1);
    return *this;
}

BloodyString& BloodyString::operator<<(const char* str)
{
    delnullter();
    core.addval((char*)str, strlen(str) + 1);
    return *this;
}

BloodyString& BloodyString::operator<<(char* str)
{
    delnullter();
    core.addval(str, strlen(str) + 1);
    return *this;
}

BloodyString& BloodyString::operator<<(string str)
{
    delnullter();
    core.addval((char*)str.c_str(), str.length() + 1);
    return *this;
}

BloodyString& BloodyString::operator<<(BloodyString str)
{
    delnullter();
    core.addval(str.char_str(), str.size());
    return *this;
}

BloodyString& BloodyString::operator<<(long long str)
{
    delnullter();
    string tmp = to_string(str);
    core.addval((char*)tmp.c_str(), tmp.length() + 1);
    return *this;
}

BloodyString& BloodyString::operator<<(char str)
{
    delnullter();
    core.push(str);
    return *this;
}

BloodyString& BloodyString::operator<<(vector<char> str)
{
    delnullter();
    string tmp(str.begin(), str.end());
    core.addval((char*)tmp.c_str(), tmp.length() + 1);
    return *this;
}

void BloodyString::setstr(const char* str)
{
    core.setval((char*)str, strlen(str) + 1);
}

void BloodyString::pushstr(const char* str)
{
    core.addval((char*)str, strlen(str) + 1);
}

size_t BloodyString::size()
{
    return _msize(core.linkbuffer);
}

void BloodyString::setbinstr(const char* str, size_t sizestr)
{
    core.setval((char*)str, sizestr);
}

void BloodyString::pushbinstr(const char* str, size_t sizestr)
{
    core.addval((char*)str, sizestr);
}

string BloodyString::string_str()
{
    string tmp;
    const auto count = _msize(core.linkbuffer);
    for (size_t x = 0; x < count; x++)
    {
        tmp.push_back(core.linkbuffer[x]);
    }
    return tmp;
}

size_t BloodyString::index(size_t val)
{
#if BSTANDART == 1
    return val;
#elif BSTANDART == 0
    return val - 1;
#endif
}

char* BloodyString::char_str()
{
    return core.linkbuffer;
}

const char* BloodyString::const_char_str()
{
    return core.linkbuffer;
}

void BloodyString::push(char sym)
{
    core.push(sym);
}


#undef fbstr
#endif

Ответы (0 шт):