how did SGI allocator handle pointer over range

H

hpsoar

It seems that SGI allocator didn't take much measures to prevent
pointer overange. Because I found that the chunk_alloc function
returns a pointer that may point to the middle of a chunk of memory
(the memory pool). Anyway, I think the most possible reason is that I
didn't know enough about the allocator, for SGI STL is really a great
STL. While If anyone can make some explanations, I'll be really
gratefull.
 
B

Bo Persson

hpsoar said:
It seems that SGI allocator didn't take much measures to prevent
pointer overange. Because I found that the chunk_alloc function
returns a pointer that may point to the middle of a chunk of memory
(the memory pool). Anyway, I think the most possible reason is that
I didn't know enough about the allocator, for SGI STL is really a
great STL. While If anyone can make some explanations, I'll be
really gratefull.

I don't think this is the allocator's responsibility.

Normally the allocator is a member of some container, and it is the
container's responsibility to check (or not check) accesses to the
storage it has allocated.

For example, std::vector has an unchecked operator[] for member
access, and an access function at() that verifies the index it is
given.


Bo Persson
 
J

James Kanze

[...]
For example, std::vector has an unchecked operator[] for member
access, and an access function at() that verifies the index it is
given.

Just a note: vector<>::eek:perator[] is NOT unchecked. A bounds
error using operator[] is undefined behavior, so it is purely a
quality of implementation issue---good implementations cause an
assertion failure, or something similar (and bad implementations
should be avoided, but you don't always have a choice).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top