Bjarne Stroustrup Technology Lecture
Transcript
And I'd just like to say that we and Morgan Stanley been overwhelmed by the moment of support and interest in this evenings event. I'd like to firstly give a huge thanks to Bjarne for giving up his time over the course of the next 2 days he's going to be presenting his lecture to probably close to 800 people between Glasgow and Edinburgh which must make it one of the biggest tech events I can remember recently in Scotland. It's fascinating to see the spirit of people in the audience with everything from people who have managed to find about the event who are still at school through academia, students, and I think there must be about 50 different Scottish technology companies with representation here so a bit of housekeeping for me 1st off could have to make sure that their mobile devices are on silent there aren't any fire drills planned for this evening so
if the fire alarm goes off the exits are each side at the front of the auditorium once we go across the road we love you all to come across and join us for some drinks nibbles at a bit of networking across in the informatics forum right across the other side of the square and again the fire doors there's one on each wall there, but for any disabled guests either go out the back wall or front entrance. In terms of people i'd like to thank, firstly my own team I'd like to say a massive thanks to Rebecca Hastings and Joe Frolly who've managed to pull together these events in just a couple of weeks. I'd also like to thank Kalid Rafiq and his team from Morgan Stanley in Scotland for all their support in making this this happen and thank Professor Dave Robertson and the Edinburgh University School of Informatics as well for their support.
After the event when we go across for the drinks a can of peas you'll see that there is a pop up there from Beit night which I'd like to take one minutes promote it's the i.t. industry's annual charity event series money for Action for Children it's a sleep that we do in a tool bar in Holyrood Park we're aiming to get at least $200.00 technologists to sleep this year and last year we raised over 100 days of payments in one night and it's to help prevent the causes of youth homelessness So there's 500 people here tonight if I can try and persuade even a fraction of you to go and speak to them and find a bit more that would be fantastic So without further ado I'd like to welcome Phil Carter who's one of the managing directors for technology at Morgan Stanley.
Was. Just checking you can hear me too I need to use the mike now that's good. So my name is Phil culture on I work in Stanley. So I run the equity trading systems. Here in Europe and focus a lot on derivatives technology and so on and so forth I hope that you watch every single slide out of the 160 slides that went up the most you're waiting for the lecture to stop won't have to tell you much about what we do but and what the are going to stand between you on the ongoing started I'm looking forward to his lecture to.
I started my career very much working as a c. programmer trying to convince my managers at the time were big for turn pro programmers not only to move to see but to move to see postbox and I was about 20 years ago and I've succeeded in doing that I'm quite pleased and I was among one of my biggest. Achievements in life I think. Anyway the to tell you a little bit about Morgan Stanley who. Now we have the great privilege of having beyond to join as our so I'll just tell you a little bit about the just briefly I think you know before I got into investment banking technology I worked in the defense industry and I didn't have a clue what those kind of being counters that.
But now been in that industry for 15 to 20 years now the you know the way I think of it more and more over that 2 decades is it is very very simple if you think and I think of the firms like Google which is essentially in my view an advertising company where the technology is really fundamental to that business. You could say that for many many other firms linked in really a recruiting agency with technology being fundamental. Oh well more and more I see what we do as being they exactly the same thing and I think you know maybe the cynics will say well of course you'd say that.
Really you know I can say that with my hand or my heart because we really couldn't run our business without it we don't run technology to support our business we run it because it's fundamental to our business. And you know one of the things we're very proud of is that. In for example the area that I work in we're number one in equity trading in the world and here in Europe and that is. You know a big part of that is because we like to think we build.
Superior technology than our competitors so we spend a lot of time trying to attract the best talent that we can track to around the world. We also try to do the best we can to nurture the talent that we have and they include languages such as c c plus plus where we invest heavily in that but also now the languages and beyond will kill me afterwards but you know other languages like jobs more recently sculler. And many many other things so you know we've recently built a new team building some of our most sophisticated platforms in Glasgow so we just I was just told we we've now hit the 100 mark you know so we have 100 programmers pin up in Glasgow working on these systems alongside 3 or 4 other key development centers we have in the world including Budapest here in Europe and in Asia we have Shanghai and Montreal in the Americas so we really look for 9 personally and I've been working.
With with teams here in Scotland during Glasgow in particular for the last 15 years and I have never had any problem attracting great talent so with that I am very pleased to come here with. Great like be on and you know be part of a lecture like this I'm looking forward to sitting down there and. Listening to the lecture so thank you very much and hope you enjoy the lecture as I'm sure our art was.
So welcome. And 1st of all I don't go around killing people. And as a matter of fact I don't think you can be a professional in the computing industry knowing just one in language so all if you actually want to be in the field you should through should learn. To preferably 5 maybe a few more. But today I will of course talk about the pros plus and I'm going to try and see what's sort of special what's essential to see plus plus and I'm not trying to to drill down and write and give you a really advanced.
Deep technical talk I'm trying to get some of the key ideas across with a simple presentation as I can get it and I'm going to use examples for a long time scale because I think it is important that systems live for a long time software tend to live quite a lot longer than hardware and people have this notion that you get all language right for the sign of figures it out and it's all there for moral. It's not takes about 10 years from inception to
serious industrial use and then it takes more decades for Everything's get done so that's what I'm going to do there are some pictures here they have or have something to do was he plus plus except for a few that obviously has nothing to do with anything they're just landscapes and such they are for me to come down take a deep breath and remember I'm going to shift the topic but the ones that appears to you straight something probably has something to do with c. plus plus that happens to be the channel of the large garden collider at Cern and one of the things I really like about programming languages about I t. is it is a perfect excuse for sticking your nose into interesting projects in just about any field and so if you're interested in high energy physics in the structure of the universe being a programmer is one of the best ways of getting there it's probably easier than becoming a theoretical physicist.
Ok so I'm going to 1st talk a little bit about what c. plus plus is and what it's supposed to be and. How how how we're getting the f. and then I'm going to go through some practical details I'm very interested in resource management mostly because on the into systems programming and building complex systems where resources has to be don't we're dealing with object oriented programming class hierarchies which Ashu most of you have seen then I'm going to get into a bit of template programming generic programming with templates and then out going to point out that you know this this is a real world language with real world problems we can do better still.
So. I listen in to. Discussions in real life and on the web and it seems that often I'm the only one around who doesn't have a firm opinion about what c. plus plus is. Hit here we see the blind men and the elephant and if all you've seen is sort of the tail you have some some firm idea of what the elephant is like except it's only right for the tail so everything we see here is probably true for somebody at some time in some place and if you think that's the whole story you're wrong and so my problem is I actually know the beast and it's a little bit hard to generalize what what the beast is when you have to take it all into account so
I'm trying to explain a little bit about the beast here about that elephant So let's go back and see what I would like what I'd like when I started see plus plus what I have learned over the years that I want type safety is a really important aspect and. When I started out a c. program couldn't check the chops of its function of there was no function prototype so it's no function declarations of specified types and this was actually fairly controversial at the time people said you know if if you have a declaration of type then when I look at my core I do not know what it's doing because it depends on something I can't see of much rather have it just like in a simply code I just do something I never have to look anywhere else.
Ok so I have actually been trying to increase the type safety of the c.c. plus plus family of languages since day one and that's not all that easy because it's on the constraints of size of programs performance of programs and such resource a 50 I really don't want to leak things if you are writing. Code for foresee a space ship and you should not run out of resources the resources can be just about anything but I think about things like memory file handles communication connections locks things like that performance my my business by and large chosen is to be able to among other things.
Run as fast as possible. Close to the hardware some language has to be able to implement memory manager and virtual machine and things like that and c. plus plus more or less by definition is that that's the aim predictability if you get into the heart real time you really have to have every operation be. Executed in a predictable time usually a low constant maximum time and over ations that can't do that are just simply not allowed on planes are.
They takeoff I'm not talking about the educate it is entertainment system of course talking about the engine controls and the things that deals with the flipping of the wings and c. plus plus photos that rule roughly except for the use of Freestore and Amec memory which is not all out there anyway and you have to do something else Cheech ability it really should be possible to Cheech how to do this kind of stuff how to use something you can't just.
Assume people will want to learn some things you have to make it reasonably easy and the complexity of the cool should be proportional to the complexity of the tusk you're doing that is a very big statement very hard to do it's an ideal it's something you can try and hope and in different domains you can get close on others but it's definitely what I would like to see and out like so have the code be readable by humans and machines again those of you will know c. plus plus knows that this is just an ideal because you can write really ugly code in c. plus plus as men effect you write really ugly code in in any language but this is a c. plus plus I'm concerned about is should be possible to write really nice readable code and pen.
And I wondered for systems programming embedded systems resource constrained systems and for large systems that's the sort of the domain I'm most interested in it is not optimized for for writing symbols web apps for instance it's not it's not meant to be the simplest programming language on earth it's supposed to be the simplest we can get it for real world constraint applications superclasses is frankly it's very expert friendly I coined the phrase to point out that that's not enough if it's only expert friendly and it's hostile to new users to novices to casual uses when are helping a lot of people that could be helped so it has to be novice friendly to that that's an important thing.
And I'll show you some code that makes this statement portable. Secret Plus comes from true traditions and programming languages and quite consciously So here is this line here which is deliberately towards a low end this is sort of close to optimal exploitation of the hardware very appealing the ability to manipulate anything you haven't hardware and. And do it well so we started with a simple Oh God languages by the sea and c c still around.
This Dennys Ritchie and his genius was actually to the define a model of hardware that was sort of general and could be used I mean if you add something use the add instruction if you access memory memory or sequences of objects when you want to compose something out of all objects you just put them next to each other you stick things of the same type next to each other and you get a raise you state things of different types on another and you get struck such That's a very nice memory model has stood the test of time very well however this is low level stuff.
I don't really like programming with bits and bytes and actresses and things like that we need something that is more fit for humans and here we have back us who invented Fortran Fortran was a language to sign for a very particular kind of humans engineers and scientists and it was the 1st language to lift the level of programming from being focused on the machine to be in focused on the problem it was the 1st language that really was fit for humans and once that was done.
We actually got portability I mean Fortran was designed so that i.b.m. could sell more machines. And it puts turned out that after Fortran you could take these programs and with fairly minor changes move them to see a Univac which was a main competitor at the time and that was I believe an unintentional effect but it was very good for us and lifting things up to a human level is is a good idea however as I pointed out scientists and engineers are very peculiar subspecies and so every once they had it their own language everybody else wanted one to Cobol being the most.
Prominent for for business but be basically very soon we had. A couple of 100 languages the problem was they couldn't talk to each other I mean when you write something and Cobol or you can do really nice record and file manipulation that was what it was for that was what the business people wondered it could add and subtract with anything more sophisticated than that it was not very good at Fortran was really good at Linear Algebra computations could handle floating point numbers now what do I do if I as a scientist wants to read some records when it's too late them and compute on the resort the answer roughly was you're out of luck. And those many many salute you chanst for this but the breakthrough I think was this.
Close new gone with the language Simula and said Why why don't you let people build their own abstractions instead of building in. Matrices and read courts and things like that why don't you just say give people the language perceive it is for building their own. Abstractions into a language so if you want a vector you build a vector if you want to 3 d. make tricks you build a 3 d. make sure if you have a record you build a record that's where the class system class concept came in and they used higher keys of classes to represent related concepts some concepts are written hierarchy oriented not or and basically you got what Hume currently known as object oriented programming languages with processes and class hierarchies and
I I found myself in a project a long time ago at the lapse where I needed to manipulate the lower levels of the hardware right memory managers right. And it worked drivers but I also needed to construct something that had a fairly high complexity of organization I wanted to be able to say this bit here runs there this big there once there no I changed my mind this British should move or there was a distributed system languages at the time that could do the hot close to the hardware programming could not say what a bit was all sort of a board of code it was still is no no serious abstraction there and
so I took the Simula class concept and put build it into c. and some of the terminology comes from Simula and it's laid up inherited by lots of all anguishes And this happen in 1980 and we've been going on for a while since. We have a new stand at the end 11 we're going to get a new one this year. It's all of the technical works being done it's going through voting procedures and so so if you want to see Explain what's he plus pluses it's from this idea of taking this cd and taking Simula and putting them together so we want to direct map from heart to heart where between the instructor structure and data types in c. plus plus coming initially from c. and you want 0 had obstruction the ability to take these things wrap them into.
New types with data or a presentation and. And and sort of operations or. Interfaces defined and then being implemented later initially from Simula one of the really key things that came in very very early in the c. plus plus. Development very early being like this that we go there about constructors and destructors because if you want to build your abstraction should we want objects of them very often the.
The object needs to be initialized and if it holds something that needs to be cleaned up you need to Cork destructor to do it and so a lot of us came in here as the advance in understanding and the number of abstract kind of abstractions we dealing with could be done and basically much of the Operate of the inspiration at the time came from operating systems my my background is an operating systems and micro programming machine architecture and such that it that explains a lot for good and bad.
And basically I've been wondering this question what will see plus plus want to be what when when it grows up and the answer. Is wants to be better at that that is c. plus plus is domain if you are in a different domain you will probably want different languages and one plus thing that people point out is that there's a lot of old crowd in c. plus plus it's like a ship that's been at sea for a long time and is a choir Bonnie calls and such and we would all like to get rid of them but we can't because long term stability compatibilities a feature he will say we want all of these new great things but we do not want you to break all coked.
This problem will probably be addressed in the future through code analysis and code transformation I hope we will see more of that but basically remember this one if you want to cross cross to be different and better. And the next question is can I break your code and I think I know the answer at least for people with large cool pieces that's that's important as opposed to a hobbyist and so here's my aversion of the elephant it's a language to sign for building basically efficient and elegant abstractions for areas were shot like software infrastructure resource constrained applications Ok so this is one of these pictures of the ads will get me to stop take a deep breath think now comes a new topic which is resource management how do we deal with with good resources.
Basically every source is something that you have to acquire and then when you're finished with it you have to give it back to wherever you got it from. And this can be explicit it can be implicit but every step of the definition of resource the example is man it is me its memory give me some memory I have to give it back over once we have a memory leak. Itself I handle open the file crucified get a lock acquire the lock release the lock open the socket connection close a socket connections things like that and we don't want leaks we really don't want the space probe to to run out of anything we don't want our cell phones to to crash once a day because it runs out of anything but electricity we can't actually handle battery life like this except of course if you run more efficiently will use less better it but that's a different issue.
And usually I mean a resource should have a known because otherwise it's really hard to know who's responsible for. Giving back resources the fact that there's no obvious representation of an owner in a in a language like c.. Plus is why these programs tend to leak. Say I make myself shake the shop on the screen and I get a pointer to that shape who is responsible for.
Getting the screen off the getting the shape off the screen again is the screen manager is Me Okey. Then I give the pointer to the shape to him this is now his job is it my that is a source of a lot of problems in n.c. started programming we need to deal with that so basically the rule is there should be a no knock that's off the handle like this that points to. The real resource the real object and the basically the handle should represent something meaningful it could be a vector it could be.
Pointed to something could could be just about anything. Ok so. In the c. plus plus standard there's actually a lot of things that behaves like that you see all of this all of the main data structures date strings maps hash tables and such or follow this model. And so whenever you have one of these it's a local object and it points to something that it manages on the side and when it goes away goes out of scope it cleans up its mist after it and it's not just memory threads logs file it's fire and streams and ship pointers are in this category so this is all over the concept was processed and that and basically they are sort of more or less look like this here is an abstraction which is a vector of cheese and so you can initialize
it in some way or the interesting classes have some way of initialising them in this place of case you can give it an initializer list of cheese and initialize a list of cheeses sort of a list of things and curly braces so here I'm saying that if you want to make a vector you have to give me an initializer list it will then make a list and it'll actually represent some way it'll set aside some memory it will put the elements of the list into that. They're turned into into that memory it keeps track of how many things the how many things it's got coming elements it's got That's about the simplest you can do and now you can make a vector of double and initialize it a vector of strings Minissha lies it and the important thing here is that when they go out of scope they hold think it's clear at all.
Notice this is not not the simplest of memory management at least Victor strength strings are themselves handled so to clean up that vector of strings I have to tell the victor to clean itself up and the victor has to tell ordered strings to clean themselves up and we could do count more complicated things like that having a vector of records with locks associated with them things like that but anyway it's very simple model you can create things and you clean up your mess when you're finished the clean up is implicit and so here is a sort of classical example you find it or no 1000000 line code bases and it's a mis Let's see what's wrong here I want to get it and say I'm a Java program or a c. plus plus programmer that still thinks it's cool to write code like in the ninety's I make myself a gadget and I assigned it to a point with a point I get back and.
There's a lot of code like that the point here is I didn't tell you what's in the get it but there could be all kinds of interesting things think it has a file handle for instance. It opens a file or something so here I do some code that might throw an exception and do something that might return and then I delete things and or good Java programmers will complain that the there has to write that elite that such a pain neck and we know that if you actually have to write such code you'd get it wrong a fair amount of time.
As a matter of fact my rule East is if I see a new one I know I have to write it leads somewhere therefore I'll get it wrong if I shouldn't write the new. But let's see. A garbage collector could be an idea it's just take away this one and everything will work except that we don't know what's inside to get it it may hold things that needs to be cleaned up so we want to do that so the naked point has a problem also if I throw an exception the gadget if I return the gadgets this is actually not good code so we can do something like this this is fairly modern c. plus plus it's been been used heavily for
the last of 1520 years in places we have a share point or I'm here using a c. plus plus 13 notation for Aids says make me a gadget and return a share point it's only a Share Point is sort of a simple implementation of garbage collection the 1st garbage collectors will worship counterpoint to things in several languages call it garbage collection to this day the point here being that if I throw an exception the destructor for that she had pointer there fires and
cleans up the mess Similarly if I return the messages cleaned up my code gets simpler There's nobody down there the Whenever we get out it gets cleaned up fine constructors and destructors handle this problem there's only one problem left is I'm not sharing anything that get it is mine or mine so why do I need to do things like get a use count to keep 2 to count the number of uses of.
Of the gadget I know the number of uses its me want so we can simplify that if you want we can make a unique pointer to a gadget and everything works simple it's simple and cheap. One of the problems with. Share pointers as they have to maintain a use count and use count as a shared resource it's shared between or uses off the pointer and so when you make more pointers to that shared object the use count goes up 12322 is when it gets to Ciro the last guy out cleans up and still cleans up everything and we don't have any leaks of file handles and such but it still if there's nothing Scheana shouldn't introduce a shared resource we are in a world where lots of forms of concurrency happens and anything shared cost more than you imagine it goes so this is better but you know
I own that gadget Why am I dealing with pointers I should have just done it simply in the 1st place there are no need for any pointers he I just make my gadget and the destructor of a gadget gets thrown if we get out of here we can get out here and get out here we can get out here doesn't matter destructor is court cleanups or reception the exceptions and that is good and basically we have reached the point where the code looks simple on there are no pointers that there are some behind the scene but it's easy to write in construction at the struct a pair that takes care of resources so there's good.
And this this this is known by the amazing phrase resource acquisition is initialization which I consider the proof that I shouldn't be in marketing and basically the dust does what we sit and it happens to be a good way of dealing with a system that uses exceptions and exceptions is the best way of dealing with error handling because it will give the right thing right happen things have to happen especially when you have destructors to help you clean out local resources and so we can write a leak free code and in general what you do is you establish an invariant in the constructor and tear it down if necessary in the destructor fine and if you don't need it destructor Well the right one now.
Where do we then use pointers we use them as references and iterators so we don't use them to represent ownership we use them to refer to objects that are owned by somebody every object should have at. A known up and this leaves one problem this problem has been there for a long time in the community people tend to want to return a lot of stuff from a function to its core like make something like make a shape make a matrix of 100000 elements some things like that it tend to use new to put it all on the Freestore and then return a pointer and the minute you do that all of the problems with pointers come back. The you have to decide who is in charge of the objects is it the creator of
the pointer or is abuse of the pointer if I share the pointer How do I know who or she added Will you basically can't solve those problems so let's let's deal with this as we have always been able to deal with a lot of these things are not new a lot of these things are not original but we have easier ways of doing them now and that's important it makes it easier for sort of the the mythical average programmer to deal with so let's consider where this picture happens the idea that you make a big thing and you need to parse it out of a function my examples with the catch it in search or work within a single scope now we're talking about communicating between scopes so there's limits to what I can do with scripts and this happens with factory functions functions that makes things and functions returning lots of object containers and things like that so let's take a classical example take an operator plus on matrices
a matrix can be big right so I take into matrices and I'm supposed to return a matrix that's a sum of the others so make a new matrix fill it up with the good stuff and return it back now in the matrix Maybe 100-005-8000 extension 00 doubles so even on a modern architecture you can tell that you probably shouldn't copy it on the way back so let's try and return a pointer that's actually not such a bright idea would get the pointer problems but it also looks ugly.
I want to deal with matrices not pointers to meters is and I don't want to go around dereferencing matrices to get their stock and apart from that how many of you spotted the bug before and I'll point it out to you as a bug right there this should not compile in any decent program and it will so anyway people say they like references better then point us so let's try this with the passing references off draw by passed by reference that's good it's trying returned by reference now this code looks nice except who deletes the object who who says delete to the point at.
Which point a where is it it's I've hidden the problem that doesn't mean that the problem went away this is almost certain to leak even faster than the examples I've shown before. Then people have solved this by saying Ok so an add operation for. Me it Major says something that generates big object should take its arguments by reference and return its occupant by reference now you have to set up a target and then program against it now we are regressing to a simply code we just lost 300 years of experience of how to write down math and related things I really don't like that this works in places a lot of this works just like dealing with the pointers directly it works
if you have enough time to deal with in your programs a simple enough but or from the out so we have to deal with them and the up years thing is that if you are making a new object you should return a new object right. Plus operation says make me a vector where the elements of the sums of the elements of my arguments so I have to return. The problem is that the semantics off returning is the semantics of copy sometimes are.
Compilers can figure out how to optimize that but it's not guaranteed so what we do here is that we return. 10000000 elements and it's painful so we try and do tricks and least tricks by and large and none did in general and try and tricky Redell that's not good so what we should do is something else and the key here is something that we all learned when we were about 6 months old right here's an object here not sure here there's nothing that so simple as that now only a computer scientist could get the idea that to get this one over there we make a copy of it put it over there and then destroy the original.
It's. Just doesn't make sense right but that's what people have more or less been doing for a long time or they built some candles with this one and moved the handle over there leaving the original in place of some more complicated stuff we need to have something really simple and the really simple looks like this Ok very naive I want a matrix that is a sum of the that has the elements of all the sum of the 2 things in return it that code should work and
we can make it work because we can make we can simply steal the representation I make are it's there it's filled with all kinds of good stuff I want to do in the **** so what I do is take this point to put it over there and make this one point to nothing so that when the destructor comes and cleans up the mess there is basically you know much to clean up and as I mention that I have been compilers or the last 20 years that could do this kind of trickery by themselves because it was an optimized version but here I'm not relying on any up to my solution so we are moving the matrix by doing 2 word copies to copy the point and if the optimizer works we can get rid of that copy too because that can be optimized away.
Anyway so this is dirt cheap and the way that code is done is to write what's called a move constructor we have constructors to construct things from basically arbitrary things we have covered constructors that define what copy means we have moved to structures that define what move means this notation here and the best c. style is cryptic and. That means some new construct and so basically copy the representation that set the representations to nothing this is it now this code works and it's sufficient even if there's 10000000 intimate c. So that is actually very simple and by the way.
You don't have to write all of these constructors yourself if you if your representation knows how to copy and move so to you the language will generate the constructors and destructors for you so if I defined a matrix as object of Davos that's the elements and by the way the vector of doubles of course knows how many doubles it contains then I don't have to write any more coke because if you move a matrix you move its representation which is the elements which knows how to move and you're finished this code here is efficient.
And leak proof exception proof and dramatically simpler than some of the code we have seen over the last many years Ok that's it so here's my comment about garbage collection. The garbage corrections neither general nor no ideal it is not general because it only takes care of memory and a lot of my resources are not memory and it's not ideal because it imposes a shared resource on the system so some of the old.
Son servers have you could get them with 64 processors and a lot of the time 63 of the processor sits waiting for the 64th to garbage collect we're better today. Somewhat better but it's still fundamentally a shared resource in a distributed world where we don't actually need to impose sharing so I you may have heard of the notion of for sharing there's an equivalent for garbage collection so what do you do keep your data in containers like that Matrix or that they are all that map but
that hash table or something like that and a menage ship with our ai the constructor destructor stuff I showed you used to constructor this will they are essentially free to move around covered constructors when you want to copy you smart pointers you need point doesn't meant 6 when do do that c. take the old shape example if I want a pointer to the interface class shape and I can deal with pointers to circles and triangles and heaven knows what.
You just use smart pointers if you are the only owner and you just want to pass it around you can use you need pointer if you are using a shared pointer if you're sharing this is the object so that you don't know who's responsible for to needing it uses yet pointer I mean when would you need to share point are classical example is that you pass some data to 3 your it doesn't task that runs in common in parallel hopefully for you you either have some docking mechanism or you have a pointer to const.
And now the last of these threads concurrent tox is supposed to clean out and the and delete the. The object pointed to the she had object and the Share Point is what really nicely for that but if all you do is to see the goose can't go one to one syrup that's not the optimal way and that's what the way they actually mostly used in existing code people use them to parse out information from inside functions.
Now then if you slowly came usually for the old code you can do what's called leader collection that is you ever so infrequently run the garbage collector like once every day because there's not that much garbage so you don't have to run it all the time and there's a standard interface to that kind of of collectors and they actually work rather well if you have a lot of old code that you can't convert to the the modern style.
So let me show some modern sucrose pass code that sort of illustrates this here I want to find all elements in the container see that that has the value of v This is just a trivial example of course so what are each turn I return a vector of pointers to the elements the value type of a container is the type of the elements and so the way I write this function obviously is make myself a container to hold the things that match and then for x. in c. if it's a match push back its address and using fair number of new c. plus plus features here there's orto that says find the type statically from the element for me to initialize a and so obviously this is the element type of the container I pass things by of reference here I don't want to have copies.
And then I return by value and I can write things like this Mary Had a Little Lamb for p.. Pointers in there that comes back from find or test that I actually. Got got the right thing back. It's a little test program that just tests the sanity of this but the point being it it may not look like the c. plus plus you're used to in c. plus plus $98.00 there's a major performance bug right there but fortunately you can't write it in c. Per's plus 98 because I loaded it up with a few c. plus plus 11 features if I'm going to use.
Move semantics I am definitely loading up the program with a few explicit features so that it breaks if you try and compile it with a c. plus plus. 98 compiler much trial on my code breaks then to get a performance bug that you might get the Ok let's look it up to Korean programming I'm going to be brief here because you all probably know it better than itu So here's the good ole shape example here except that it take a victim of unique pointers to ship through is the president example where you want to put a morphic pointer I.
Loped a vector up with a call before objects which I create using make unique says make me a circle and give me back a unique point of Ok nodes note the absence of news note the absence of raw pointers that are just the represent station of the extras in memory and now I said draw them or not go for all of them and core drop I'll get back to what a drop will sequences later. So that that's fairly simple and it is the classical object oriented example except that this one hears is fairly brief and doesn't leak at Tor.
Of course shape looks the way it has done for a long time. Would virtual from the senior guys that invented the mechanism and I book just as I borrowed the word. Class from them why does in court type Well it was simular was invented by mathematicians and it seemed natural to them. And thin the only thing that's new here is that you can be explicit about overriding you want to say that must be a draw with this type it takes no argument to return to a void in the base class for me to or I target some chick just slight it will refinement that some people like you don't have to do it if you don't like it the protection model is public protected and private be aware of protected it will cause blogs for you if you use it for

Ask anything
We've read this whole study set, so questions about it get the best answers.