Hi,
Given:
1) Custom containers that have nothing to do with vector, deque, list,
map etc,
2) a custom version of new and delete defined for these containers,
customNew and customDelete, say. When an item is to be inserted/removed
into/from these custom containers, customNew and customDelete is
called.
3) Iterators are available for these custom containers which adhere to
the requirements of stl.
e.g.
CustomContainer cc.
cc.add(somethin g); // will call customNew whenever memory needs to be
allocated
cc.remove(somet hing) // will call customDelete whenever memory needs to
be deleted
for (CustomContaine r::iterator i = cc.begin(), i!=cc.end(); ++i)
{
// do stuff to each element;
}
Now assuming I have an allocator defined such that customNew and
customDelete will be called instead of the defaults/usual new/delete, I
need to know how arrange things such that customNew and customDelete
will be called for the container by the STL algorithms.
If I look at how I would use custom allocators for say a std::vector,
I would do something like this (given my_allocator is defined)
std::vector<int , my_allocator<in t> > intVect;
std::sort(cc.be gin(), cc.end()); // sort will use my_allocator for
memory alloc/dealloc etc.
however my custom containers know nothing about allocators. I can get
std::vector to use my_allocator for (de)/allocations, but I can't see
how I can get the stl algorithms to use my_allocator with my custom
containers. I have all the parts but I can't seem to glue them all
together, if that makes sense.
So in order to have this code;
myContainer<int > intCont;
intCont.add(2)) ; // will call customNew if necessary
intCont.remove( 2); // will call customDelete if necessary
// these iterators adhere to the stl requirements for randomaccess
iterators.
myContainer::it erator begin = intCont.begin() ;
myContainer::it erator end = intCont.end();
// now heres the rub.
std::sort(begin , end);
I want these alorithms to use customNew and customDelete to get memory
if needed,.
I thought I had to use allocators originally but know I'm thinking
thats not the case. What exactly do I need to do to have std::sort
(and other algorithms) use customNew and customDelete.
thanks 2 1600 bo*@blah.com wrote: Hi,
Given:
1) Custom containers that have nothing to do with vector, deque, list, map etc, 2) a custom version of new and delete defined for these containers, customNew and customDelete, say. When an item is to be inserted/removed into/from these custom containers, customNew and customDelete is called. 3) Iterators are available for these custom containers which adhere to the requirements of stl.
e.g.
CustomContainer cc. cc.add(somethin g); // will call customNew whenever memory needs to be allocated cc.remove(somet hing) // will call customDelete whenever memory needs to be deleted
for (CustomContaine r::iterator i = cc.begin(), i!=cc.end(); ++i) { // do stuff to each element; }
Now assuming I have an allocator defined such that customNew and customDelete will be called instead of the defaults/usual new/delete, I need to know how arrange things such that customNew and customDelete will be called for the container by the STL algorithms.
If I look at how I would use custom allocators for say a std::vector, I would do something like this (given my_allocator is defined)
std::vector<int , my_allocator<in t> > intVect;
std::sort(cc.be gin(), cc.end()); // sort will use my_allocator for memory alloc/dealloc etc. however my custom containers know nothing about allocators. I can get std::vector to use my_allocator for (de)/allocations, but I can't see how I can get the stl algorithms to use my_allocator with my custom containers. I have all the parts but I can't seem to glue them all together, if that makes sense.
So in order to have this code;
myContainer<int > intCont; intCont.add(2)) ; // will call customNew if necessary intCont.remove( 2); // will call customDelete if necessary
// these iterators adhere to the stl requirements for randomaccess iterators. myContainer::it erator begin = intCont.begin() ; myContainer::it erator end = intCont.end();
// now heres the rub. std::sort(begin , end);
I want these alorithms to use customNew and customDelete to get memory if needed,.
I thought I had to use allocators originally but know I'm thinking thats not the case. What exactly do I need to do to have std::sort (and other algorithms) use customNew and customDelete.
Most STL algorithms are structured in a way so that they don't have to
call any memory allocators at all.
std::sort does not have to allocate or deallocate memory, and I can't
think of any of the algorithms in <algorithm> or <functional> headers
that would need to allocate or deallocate memory.
On 2005-12-13, bo*@blah.com <Gr**********@g mail.com> wrote: Hi,
Given:
1) Custom containers that have nothing to do with vector, deque, list, map etc, 2) a custom version of new and delete defined for these containers, customNew and customDelete, say. When an item is to be inserted/removed into/from these custom containers, customNew and customDelete is called. 3) Iterators are available for these custom containers which adhere to the requirements of stl.
// these iterators adhere to the stl requirements for randomaccess iterators. myContainer::it erator begin = intCont.begin() ; myContainer::it erator end = intCont.end();
// now heres the rub. std::sort(begin , end);
I want these alorithms to use customNew and customDelete to get memory if needed.
I thought I had to use allocators originally but know I'm thinking thats not the case. What exactly do I need to do to have std::sort (and other algorithms) use customNew and customDelete.
The standard algorithms don't need to allocate or release memory.
They just assign and copy elements. You need to pass special
inserter iterators to get the behavior you're thinking of.
For example:
MyContainer<int > unique_list;
std::unique_cop y(begin, end, std::back_inser ter(unique_list ));
That will work for your container as long as it supports
MyContainer::pu sh_back.
--
Neil Cerutti This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JellBell |
last post by:
I dont know what is a legacy system..please help me out
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
|
by: phil_gg04 |
last post by:
Dear C++ Experts,
Over the last couple of months I have been writing my first program
using shared memory. It has been something of an "in-at-the-deep-end"
experience, to say the least. At present the shared memory contains a
few fixed-size structs, but I really need to be able to store more
complex variable-sized data in there. So the next task is to work out
how to store C++ objects, and if possible STL containers, in this
shared...
|
by: Matthias Kaeppler |
last post by:
Hi,
in my program, I have to sort containers of objects which can be 2000
items big in some cases. Since STL containers are based around copying
and since I need to sort these containers quite frequently, I thought
it'd be a better idea to manage additional containers which are
initialized with pointers to the objects in the primary containers and
sort those (only pointers have to be copied around then).
However, that also means if I...
|
by: Sai Kit Tong |
last post by:
I posted for help on legacy code interface 2 days ago. Probably I didn't
make it clear in my original mail. I got a couple of answers but none of
them address my issues directly (See attached response). My first reply
directed me to source code migration but I didn't have the source code. The
second reply mentioned about .NET interoperability (PInvoke I think) but I
MENTIONED THAT I COULDN'T FIND ANY DOCUMENTATION FROM MSDN LIBRARY BASED ON...
|
by: Mark Olbert |
last post by:
First off, the sympathy is for all you poor buggers out there who have to figure out how to marry
Managed Extensions for C++ onto your legacy code. My condolences; my brief experience with the
process leads me to believe the Microsoft hates all of its VC++ developers :)
Now, the question. I'm getting a NullReferenceException in a __gc class that wraps functionality in
a legacy C/C++ app (it's actually part of the Nero burning rom api).
...
| |
by: Gregory |
last post by:
I have a question about using STL containers in C++ class public
interface.
Lets say that I want to return some container from class method or
accept class method parameter as some container. For example:
class A
{
public:
const vector<int>& getTable() { return m_table; }
|
by: Jean-Marc Blaise |
last post by:
IBM recommends to place each ts container on a different physical disk.
What about the impacts if all containers (DMS) are in the same FS (supported
by multiple disks) ?
Does DB2 preallocate doing // IO, so we could assume to have, for 2
containers as exemple:
Ext1ct1, Ext1ct2, Ext2ct1, Ext2ct2
|
by: Jason Madison |
last post by:
I would like to create a .net application that still uses a few screens from
an old legacy application we have.
I can list records from the database in my .net app, but when it comes to
making updates I still need to legacy screens as the update logic is very
complex.
I have found I can use SetParent to "embed" some of the legacy screens
within my .net app, but because they are still basically two separate
applications clicking...
|
by: Nindi73 |
last post by:
HI
If I define the class DoubleMap such that
struct DoubleMap : public std::map<std::string, double>{};
Is there any overhead in calling std::map member functions ?
Moreover are STL containers destructors virtual >
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |