Skip to content

Commit

Permalink
Introduce size *estimate* for record cache allocated size
Browse files Browse the repository at this point in the history
  • Loading branch information
omoerbeek committed Jan 14, 2025
1 parent 8d53ff6 commit 3a8ec14
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 23 deletions.
7 changes: 7 additions & 0 deletions pdns/dnsname.hh
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ public:
return d_storage;
}

[[nodiscard]] size_t sizeEstimate() const
{
return d_storage.size(); // knowingly overestimating small strings as most string
// implementations have internal capacity and we always include
// sizeof(*this)
}

bool has8bitBytes() const; /* returns true if at least one byte of the labels forming the name is not included in [A-Za-z0-9_*./@ \\:-] */

class RawLabelsVisitor
Expand Down
12 changes: 12 additions & 0 deletions pdns/dnsparser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ public:
d_locked.store(true);
}

[[nodiscard]] virtual size_t sizeEstimate() const = 0;

protected:
typedef std::map<std::pair<uint16_t, uint16_t>, makerfunc_t* > typemap_t;
typedef std::map<std::pair<uint16_t, uint16_t>, zmakerfunc_t* > zmakermap_t;
Expand Down Expand Up @@ -433,6 +435,11 @@ public:

return *d_content == *rhs.d_content;
}

[[nodiscard]] size_t sizeEstimate() const
{
return sizeof(*this) + d_name.sizeEstimate() + (d_content ? d_content->sizeEstimate() : 0U);
}
};

struct DNSZoneRecord
Expand Down Expand Up @@ -469,6 +476,11 @@ public:
return d_record;
}

[[nodiscard]] size_t sizeEstimate() const override
{
return sizeof(*this) + d_dr.sizeEstimate() + d_record.size();
}

private:
DNSRecord d_dr;
vector<uint8_t> d_record;
Expand Down
Loading

0 comments on commit 3a8ec14

Please sign in to comment.