dimanche 3 janvier 2021

delete causes core dumped, and why?

I encountered core dump when delete the array new without delete[]

here is my code:

Page *p;
p = new Page[10];
delete p;

but when I try to delete int[], there seems nothing

here:

int *p;
p = new int[10];
delete p;

I want to know why the first example causes the core dump but the second runs perfectly?

This is my calss.

class Page {
public:    
    Page() {
        page_id_ = INVALID_PAGE_ID;
        pin_count_ = 0;
        is_dirty_ = 0;
        reset_mem();
    }

    ...
private:
    void reset_mem() { memset(data_, 0, PAGE_SIZE); }

    std::atomic<page_id_t> page_id_;
    std::atomic<int> pin_count_;
    std::atomic<bool> is_dirty_;
    std::atomic<lsn_t> lsn_;

    char data_[PAGE_SIZE];

    ReaderWriterLatch latch_;
};

Thank You!

Aucun commentaire:

Enregistrer un commentaire