TAILIEUCHUNG - C for game programmers phần 7

Nó mô tả phổ biến C + + kỹ thuật để giải quyết các vấn đề cụ thể phải đối mặt bởi hầu hết các nhà phát triển, và tập trung vào các kỹ thuật đã được chứng minh trong các trò chơi thực sự. Ngoài ra, công nghệ cụ thể như STL được trình bày chi tiết, | Chapter 9 STL Algorithms and Advanced Topics 243 pointer allocate size_type nNumObjects const void hint 0 return static_cast pointer new nNumObjects sizeof T pHeap void deallocate pointer p size_type nNumObjects deletefp nNumObjects sizeof T . There is a slight problem here. How do we pass pHeap into the operator Ideally we would like the allocator to keep a pointer to the heap we want to use and pass it to new every time there is an allocation. Here comes the first quirk of STL allocators allocators should not have any per-object stale. So we cannot keep a pointer to the heap. To get around that we need to create a quick wrapper class around our heap and use that class as a parameter into the allocator template. Here is a new attempt at writing the allocator class HeapGraphics public static void allocate size_t nNumBytes return new nNumBytes s_pGraphicsHeap static void deallocate void p size_t nNumBytes delete p nNumBytes template typename T typename Heap MyHeapAllocator public pointer allocate size_type nNumObjects const void hint 0 return static_cast pointer Heap allocate nNumObjects sizeof T pHeap void deallocate pointer p size_type nNumObjects Heap ídeallocate p nNumObjects sizeof T Team LRN 244 C for Game Programmers This new version respects all the rules of allocators and allows US to allocate all memory from our own heap. The only drawback is that we need to create one wrapper class for every heap we want to use which could be a nuisance. As has been mentioned though STL allocators are not perfect. The actual workings of the insides of allocators are a bit more involved but from a user s point of view this is all you need to know to get up and running at writing your own custom allocators. Refer to some of the sources listed in Suggested Reading at the end of this chapter for some interesting reading on allocators. WHEN STL Is NOT ENOUGH Advanced Ironically after spending several whole chapters discussing how STL can be a real benefit to your game project

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.