Posts

Showing posts with the label cpp_e

Smart pointer_application

Image
Let's look at shared_ptr's applications and problems we are often faced with. There are beautiful examples in data structure such as linked-list and tree. In this post, we will take tree example. Before learning shared_ptr, it is common to use normal pointer to save children node's information. When taking tree structure, we can use shared_ptr instead of normal pointer since every node is usually allocated in heap memory. Advantage, when using shared_ptr, is ofcurse automatic  memory releasing. In existing tree structure, Node class should be deleted from high level(or leaf node). So we create  wrapping class called 'tree' and use postorder algorithm to release memory. However Node class ,used with shared_ptr, doesn't need wrapper one and also dose not need to do anything in destructor. Memory will be released automatically in an ordered way. For example, when node is deleted, deleting shared_ptr also follows. Then, shared_ptr's de...

Smart pointer

Image
This post is about shared_ptr in C++11. We will take a look at (dis)advantages of shared_ptr and how to use it. Usually we are only aware of advantages of smart pointer. Through this post, I hope we freely talk about disadvantages also.   Smart pointer? First of all, It isn't reasonable not to talk about smart pointer. Smart pointer is what designed for preventing user from memory leak when user forgot to delete dynamic memory allocation. 'Automatic memory-care pointer' is enough to understand smart pointer. You can see advantage of smart pointer preventing mistake from below example.   Someone assign other address to normal_pointer eventhough it has already address of heap memory. If heap memory will be used after, developer should save its address to other pointer and if heap will not be used, delete operator is neeeded. But we often do these mistakes. It might be arrogant trusting oneself can care all of memory. To see whether memroy is del...

C++ Visual studio_ how to use

Image
Hello, In this post, we will see how to use Visual studio with some pictures. This is not a writing for 'what is c++' or 'how to study c++'. It's just knowing basic tool for using visual studio like 'how to make new project', 'where can we find our project' and 'how to add existing source files'. And I posted some mistakes people usually make. Surprisingly, there are common trivial mistakes I have seen. I think person who starts learning c++ 'will have or had' that problem. Ok. let's see first how to download visual studio. go to  https://www.visualstudio.com/ , click the button download and download visual studio! visual studio community is free. It is on your mind what version you want to download. I'm using visual studio 2015 but 2013 also fine. It is not a hard work to download yourself. If you have some problems downloading visual studio, please comments in this post. Maybe that will not be hard to be solved....