三种的allocator实现源代码的对比(三)

2014-11-24 09:57:58 · 作者: · 浏览: 7
s in the mapped region.
*/
virtual int protect (ssize_t len = -1, int prot = PROT_RDWR) = 0;

/// Change the protection of the pages of the mapped region to @a prot
/// starting at @a addr up to @a len bytes.
virtual int protect (void *addr, size_type len, int prot = PROT_RDWR) = 0;

#if defined (ACE_HAS_MALLOC_STATS)
/// Dump statistics of how malloc is behaving.
virtual void print_stats (void) const = 0;
#endif /* ACE_HAS_MALLOC_STATS */

/// Dump the state of the object.
virtual void dump (void) const = 0;
private:
// DO NOT ADD ANY STATE (DATA MEMBERS) TO THIS CLASS!!!! See the
// implementation for explanation.

/// Pointer to a process-wide ACE_Allocator instance.
static ACE_Allocator *allocator_;

/// Must delete the if non-0.
static int delete_allocator_;
};

最近自己也写了几个allocator,还没有研究更好的实现方式。不过看上去,侯先生书上说空间配置器,我应该可以考虑一下读取硬盘空间来做allocator的空间,虚拟内存估计就是这么实现的吧。

随想:回想一年前,我第一次使用标准库,觉得allocator实现是很高深的学问,自己什么时候才能学会啊。后来看侯先生的allocator这本书,觉得我也可以做到,但由于自己的懒惰,很久都没有实践,最近有时间,再把标准库认认真真的读一下,写一些深得体会,也对得起自己这三年的工作学习。其实有很多事情,一开始觉得那么高深而自己难为之,只要有信心,方法用对了,坚持下来就会有突破的,而且一旦突破,那种快乐是相当舒服的。

最近有一个用了C++快五年的程序员,对C++及开源的了解相当深入,我觉得他也是一步一步走过来的。对于一些元编程,模板的灵活用法,网络编程的高级使用,服务器的负载均衡,linux内核机制,window底层原理,他都有所深入了解,他现在说的很多我都还不懂,我需要坚持自己的步伐,加快一点。