联盟首页 协同开发 共创软件 开放源码 软件工程 共创论坛 关于联盟
  您的位置 » 开放源码库【成熟 - 项目摘要 首页 | 分类源码 | 提交源码 | 下载统计 | 原创源码 | 成熟源码 | 代码片断
 
 A Safer STL Container Class - 项目摘要
摘要 | 管理 | 论坛
文档 | 软件包

源码库中源码数量为19221
有贡献人员名单:

-= 更多 =-
  • ffdshow
  • jasperreports
  • PoolMan
  • Air Traffic Controller
  • virtualdub-win
  • CppUnit
  • Apache-SSL-Jserv
  • FCK editor
  • Async Professional
  • GLgraph
  • -= 更多 =-

    项目描述:
    I like to use STL containers because they are generic and fast. If you need to store many pointers to objects then STL works great and is very reliable. My problem is that I cannot trust myself. Sometimes I store a pointer in STL map and delete the object later. When the time comes to use the object again, the map has no knowledge about the object being deleted elsewhere so it returns a pointer to some memory location. The pointer is not NULL but the object is long gone. This is especially unanticipated when I use map across multiple threads. So I've created a simple wrapper class for the STL map called CTidyMap. It is far from being a "super code", but someone might find it useful. My solution is to place an unsigned int to be the first element in the object and fill it up with some magic number (I used 0xfeedface). Every time CTidyMap has to return a pointer to the object it checks the magic number first, so your program does not end up with bad pointer.

    我比较喜欢使用STL的窗口类,因为它们是通用的,速度快。如果你需要保存许多对象的指针,那么STL工作得很好也很可靠。我的问题是我不相信自己。有时我在STL map中保存一个指针,并在以后删除了对象。当再一次使用对象时, map 不知道对象已经被删除了,所以它返回指向内存某一位置的指针。指针不为NULL,但对象已经不存在了。在使用多线程应用程序中,尤其无法预见这一情况。这时提供的不是一个完美的代码,但有人可能会觉得有用。我的解决办法是用一个无符号整数作为对象的第一个元素,用一个幻数填充它(我使用 0xfeedface)。每当CTidyMap 返回一个对象指针时,它先检查这个幻数,所以你的程序不会因为坏指针而崩溃。
    来源: http://www.codeguru.com/cpp_mfc/stlContainer.shtml
    类别:
    发布者: cbd002

    最新发布源码包
    软件包 版本号 日期 本地下载
    stlContainer  1.0  2004-04-15 下载

    原始下载连接(国外) http://www.codeguru.com/code/legacy/cpp_mfc/stlContainer.zip

      » 合 作 伙 伴