473,789 Members | 2,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

allocator.destr oy()

Why does the value of the below int pointer not disappear after using
destroy:

std::allocator< intallo;

int* ip;
allo.construct( ip,777);
std::cout << "*ip = " << *ip << std::endl;

allo.destroy(ip );
std::cout << "*ip = " << *ip << std::endl;

I get two prints with 777.
Jun 4 '07 #1
3 2775
desktop wrote:
Why does the value of the below int pointer not disappear after using
destroy:

std::allocator< intallo;

int* ip;
allo.construct( ip,777);
std::cout << "*ip = " << *ip << std::endl;

allo.destroy(ip );
std::cout << "*ip = " << *ip << std::endl;

I get two prints with 777.
What do you think "destroy" does ? What do you expect it to do ?

It's undefined in this case. It might print 777 on your platform, it
might not on mine and it might melt the cpu on other platforms.
Jun 4 '07 #2
On 4 Juni, 23:14, Gianni Mariani <gi3nos...@mari ani.wswrote:
desktop wrote:
Why does the value of the below int pointer not disappear after using
destroy:
std::allocator< intallo;
int* ip;
allo.construct( ip,777);
std::cout << "*ip = " << *ip << std::endl;
allo.destroy(ip );
std::cout << "*ip = " << *ip << std::endl;
I get two prints with 777.

What do you think "destroy" does ? What do you expect it to do ?

It's undefined in this case. It might print 777 on your platform, it
might not on mine and it might melt the cpu on other platforms.
Did I read you post wrong? Because to me it seems like the call to
destroy is quite defined while the last line (where the pointer is
dereferenced) is undefined.

--
Erik Wikström

Jun 5 '07 #3
Erik Wikström wrote:
On 4 Juni, 23:14, Gianni Mariani <gi3nos...@mari ani.wswrote:
>desktop wrote:
>>Why does the value of the below int pointer not disappear after using
destroy:
std::allocator< intallo;
int* ip;
allo.construct( ip,777);
std::cout << "*ip = " << *ip << std::endl;
allo.destroy(ip );
std::cout << "*ip = " << *ip << std::endl;
I get two prints with 777.
What do you think "destroy" does ? What do you expect it to do ?

It's undefined in this case. It might print 777 on your platform, it
might not on mine and it might melt the cpu on other platforms.

Did I read you post wrong?
The second sentence refers to the code in the post - in particular the
second *ip.
... Because to me it seems like the call to
destroy is quite defined while the last line (where the pointer is
dereferenced) is undefined.
Yeah - it may be stated in an ambiguous way.
Jun 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1533
by: Orjan Westin | last post by:
Hi, I have an interesting (read frustrating) problem. I'm writing a generic container class, which holds data as well as links to other instances of itself, like this: template<class T> class node { public:
15
4277
by: Alex Vinokur | last post by:
I am looking for any custom allocator sample code for std::vector. Thanks. -- Alex Vinokur http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn
7
3081
by: Grahamo | last post by:
Hi, can anybody tell me where I can get the boiler plate code for std::allocator. I need to have my version of new and delete called and want to get reference code. My compilers headers are all over the place with #ifdefs and what not, I'd like a clean copy. thanks much
4
1385
by: Sepidar | last post by:
hi all, I'm trying to write a custom allocator for myself, using with std::jvector. But it seems that I have no response from it. See the code: #include <iostream> #include <vector> #include <memory> using std::cout;
3
4656
by: Mike | last post by:
Hi, I have a simple "memPool' class that simply maintains a linked list of chunks from which allocation requests are made. The whole thing is deleted all at once upon destruction. So far, so good. Then I tried to make an allocator for this and use it with std::list with no success. I modeled my allocator code from gcc's new_allocator.h. I modified the allocate() and deallocate() functions and copy constructors, and added a...
5
1305
by: Chris Thomasson | last post by:
Does this program produce any undefined-behavior: http://pastebin.com/m5eb3c81a ?
16
2703
by: PeterAPIIT | last post by:
Hello all C++ expert programmer, i have wrote partial general allocator for my container. After reading standard C++ library and code guru article, i have several questions. 1. Why allocator write forward declaration then allocation for void* rather than directly wrote allocator first ?
13
2079
by: Phil Bouchard | last post by:
I am currently writting a smart pointer which is reasonnably stable and I decided supporting allocators for completion because of its increase in efficiency when the same pool used by containers is shared. I was told the new standards are being finalized and I am hoping minor but important changes could be applied before anything else. To give a quick overview on the current status of this topic, you will find below the latest text...
8
3170
by: Chris M. Thomasson | last post by:
Here is the initial crude implmentation which compiles under Comeau with no warnings: ___________________________________________________________________ #include <cassert> #include <cstdlib> #include <new> #include <list> template<typename T, std::size_t BUFDEPTH = 1024>
0
9666
marktang
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...
0
9511
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,...
0
10410
Oralloy
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...
1
10139
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,...
1
7529
isladogs
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...
0
5418
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...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.