Closed Bug 1380410 Opened 2 years ago Closed 2 years ago

Add mozilla::NeverAllocPolicy

Categories

(Core :: MFBT, enhancement)

enhancement
Not set

Tracking

()

RESOLVED FIXED
mozilla56
Tracking Status
firefox56 --- fixed

People

(Reporter: Nika, Assigned: Nika)

Details

Attachments

(1 file)

For some situations, such as in bug 1380096, it's useful to use MFBT types like Vector in situations where it would be Very Bad(tm) to allocate any memory.

For those situations, I suggest we add mozilla::NeverAllocPolicy, which is an alloc policy like MallocAllocPolicy, except it always fails to allocate, returning `nullptr`.
MozReview-Commit-ID: 8U38Oj3vyaF
Attachment #8885833 - Flags: review?(erahm)
Comment on attachment 8885833 [details] [diff] [review]
Add NeverAllocPolicy

Review of attachment 8885833 [details] [diff] [review]:
-----------------------------------------------------------------

LGTM, but we should get a mfbt peer to sign off. Mike this is pretty straightforward and came out of a discussion in another bug, a simplified version of the usage we were talking about would be to replace something like:

> char buffer[kMax];
> size_t used = std::min(str.len, kMax);
> memcpy(buffer, str, used);

with:

> Vector<char, kMax, NeverAllocPolicy> buffer;
> buffer.append(str, used);
Attachment #8885833 - Flags: review?(mh+mozilla)
Attachment #8885833 - Flags: review?(erahm)
Attachment #8885833 - Flags: review+
(In reply to Eric Rahm [:erahm] (please no mozreview requests) from comment #2)
> LGTM, but we should get a mfbt peer to sign off.

Oops. for some reason in my head you were a mfbt peer ^.^.
Attachment #8885833 - Flags: review?(mh+mozilla) → review+
https://hg.mozilla.org/mozilla-central/rev/0318e26f75c8
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla56
You need to log in before you can comment on or make changes to this bug.