- (quest) interesting benchmark - 3 Updates
- Is new-allocation needed anymore? - 10 Updates
- The Story of Jesus and Mary in the Holy Quran (part 1 of 3): Mary - 1 Update
- Is new-allocation needed anymore? - 4 Updates
- A "better" C++ - 4 Updates
- tdm gcc 5.1 slower than 4.7 - 1 Update
- Noob question: does a library exist to output data to a logical input serial com port - 1 Update
- static guard locks - 1 Update
Prroffessorr Fir Kenobi <profesor.fir@gmail.com>: Aug 30 12:43PM -0700 this is some benchmark i fond on some blog (called 'null program') #include <stdio.h> #include <stdlib.h> int trial() { int count = 0; double sum = 0; while (sum <= 1.0) { sum += rand() / (double) RAND_MAX; count++; } return count; } double monteCarlo(int n) { int i, total = 0; for (i = 0; i < n; i++) { total += trial(); } return total / (double) n; } int main() { printf("%f\n", monteCarlo(100000000)); return 0; } this measures if i understuud the problem how many random values (form 0. to 1.) to add to get a sum over 1.0 (it could be thinked maybe that it shold be 2 on average but it soes not seem so (or maybe im wrong in understanding it) dont matter) They say that it is e = 2.71828... this is anyway interesting form the optimistation points of view, this kode above on my old C2D executes 7.6 s and yeilds to 2.178154 the quest optimise it.. to optimise it i think there should be written a better rand() routine that both would have good probabilistic properties and faster execution.. can someone provide such routine? |
Johann Klammer <klammerj@NOSPAM.a1.net>: Aug 30 11:13PM +0200 On 08/30/2015 09:43 PM, Prroffessorr Fir Kenobi wrote: > 2.71828... > this is anyway interesting form the optimistation points of view, > this kode above on my old C2D executes 7.6 s and yeilds to 2.178154 Looks closer to 2 than e.... > written a better rand() routine that both would have good > probabilistic properties and faster execution.. > can someone provide such routine? take the code for rand and the functions it calls from the c library and inline them in this file. |
Prroffessorr Fir Kenobi <profesor.fir@gmail.com>: Aug 30 02:21PM -0700 W dniu niedziela, 30 sierpnia 2015 23:13:44 UTC+2 użytkownik Johann Klammer napisał: > > probabilistic properties and faster execution.. > > can someone provide such routine? > take the code for rand and the functions it calls from the c library and inline them in this file. where is that code? (changing div to mul by inverse improves quite a lot 7.6 -> 5.6 or alike,, but really wonder if some better than clib rand cannot be found.. are all this various platform rands() implement the same algorithm? |
jt@toerring.de (Jens Thoms Toerring): Aug 30 11:29AM > containers, vectors and smart pointers. So was just thinking is there > any situation where we would need to use new and we can not use vector > instead? Short answer: what would you have a smart pointer hold but a pointer to allocated memory (typically allocated with 'new')? Dynamic arrays isn't the only place 'new' would be needed (but they can indeed be avoided by using a vector, but then the vector class itself will need to allocated memory as has been pointed out). Actually, your question could be seen as part of a bigger one: do we need pointers at all anymore (except for interfacing with legacy code)? One example where you definitely need pointers: you want to store a set of class instances, all derived fromt he same base class, in a vector - e.g. all animals on a farm, so you have an 'Animal' base class and derived 'Cow' and 'Pig' classes. You might be tempted to use something like std::vector< Animal > v; v.push_back( Cow( ) ); v.push_back( Pig( ) ); But when you then call a method of the elements of the vector, i.e. v.back( ).foo( ); the 'Animal' base class method will be invoked, not the method of the derived 'Pig' class! And you wouldn't even be able to create a vector of 'Animal' instances if 'Animal' contains pure virtual methods and thus can't be instantiated. But if you do instead std::vector< std::unique_ptr< Animal > > v; v.push_back< std::unique_ptr< Animal >( new Cow ) ); v.push_back< std::unique_ptr< Animal >( new Pig ) ); then v.back( )->foo( ); will nicely invoke the method from 'Pig' overriding the one from 'Animal'. That's one example where pointers are required - and when you have pointers you typically also want to be able to make them point to dynamically allocated objects (unless maybe if you know in advance exactly how many are going to be used). And for that you definitely want 'new' (or some other form or allocation). Regards, Jens -- \ Jens Thoms Toerring ___ jt@toerring.de \__________________________ http://toerring.de |
JiiPee <no@notvalid.com>: Aug 30 02:07PM +0100 On 30/08/2015 12:29, Jens Thoms Toerring wrote: > v.back( )->foo( ); > will nicely invoke the method from 'Pig' overriding the > one from 'Animal'. I was more like talking about the pair new-delete so doing the memory management using them alone. In which situation that would be good? |
JiiPee <no@notvalid.com>: Aug 30 02:08PM +0100 On 30/08/2015 13:53, Stefan Ram wrote: > A pointer to allocated memory, typically allocated with > a make function. > auto object = ::std::make_unique< A >( args ); yes, this looks good/better. Although I dont think you need that ::std:: ... just std:: |
bartekltg <bartek@gmail.com>: Aug 30 03:58PM +0200 It looks like my server doesn't update this newsgroup anymore. On 29.08.2015 14:15, JiiPee wrote: >> resevre(n) allocata 'at least n'. shrint_to_fit is only a sugestion. > Ok so if we need a vector which behaves differently than std::vector. > I think std::vector should have an option to set capacity = size. And we have since c++11. It is shrink_to_fit I was talking about. but i may not work: " void shrink_to_fit(); 14 Remarks: shrink_to_fit is a non-binding request to reduce capacity() to size(). [ Note: The request is non-binding to allow latitude for implementation-specific optimizations. — end note ] " > A bit strange to create my own vector class just because the std version > allocates too much memory. the capacity functionality > should be maybe optional? why is it not? Because vectro should be ready for multiple 'push_back'. If you always keep only enough memory, vector <double> tab; for (int i=0;i<N;++) tab.pushback(sin(0.1*i)); will be quadratic. A standard solution for that is to allocate "too much" memory. Then it is linear. vector is a very good universal container. But sometimes a feature, needed 99% of times, is not optimal for you. > but can't you use std::valarray for that? it does not have capacity I can. It even may be better for compiler to optimize the code. bartekltg |
bartekltg <bartek@gmail.com>: Aug 30 04:08PM +0200 On 30.08.2015 13:29, Jens Thoms Toerring wrote: > Short answer: what would you have a smart pointer hold but > a pointer to allocated memory (typically allocated with > 'new')? A pointer to any object I don't want to keep as static variable. For example, like you have said, for polymorphism. The array of object is exactly the one place where you should use a container (vector), not a chunk of manually allocated memory. > (but they can indeed be avoided by using a vector, but then > the vector class itself will need to allocated memory as has > been pointed out). I understand that OP ask about 'a normal user' should use news, not someone who write standard library. In other words, where we should take allocation in our hands instead of using containers. > Actually, your question could be seen as > part of a bigger one: do we need pointers at all anymore > (except for interfacing with legacy code)? I think it is very different question. Of course the answer is still the same: yes, we need new/delete; yes, we need pointers, both smart and raw. bartekltg |
JiiPee <no@notvalid.com>: Aug 30 03:34PM +0100 On 30/08/2015 15:08, bartekltg wrote: > use news, not someone who write standard library. > In other words, where we should take allocation in our hands > instead of using containers. yes, and using possible delete as well (or if smar pointers, then reset). so total management |
JiiPee <no@notvalid.com>: Aug 30 04:12PM +0100 On 30/08/2015 15:55, Stefan Ram wrote: > When Stroustrup teaches C++, he shows us how to implement > a Vector class early (at about 4% of the book) in his book > »The C++ programming language«. but I think he adds many times, that dont do this at home but use rather std versions.. |
bartekltg <bartek@gmail.com>: Aug 30 05:37PM +0200 On 30.08.2015 16:55, Stefan Ram wrote: > When Stroustrup teaches C++, he shows us how to implement > a Vector class early (at about 4% of the book) in his book > »The C++ programming language«. The idea behind STL is that you do not have to write you own vector. I can write ma own container, sorting algorithm, matrix library, graphic library(probably;))... but in most cases I should not. I will try rephrase the question one more time: Someone is building a class. The class have a set of data. We can do it by including std::vector<whatever> as a member (and this is a preferable solution for most cases) or by manually allocating (freeing, keeping eye on usage and reallocating) memory. And OP is asking, when he should go with second option and do more work. One example is when we do not need a frequent small resizing, and want to keep additional memory usage low. I'm sure this is not the only one. bartekltg |
bartekltg <bartek@gmail.com>: Aug 30 05:57PM +0200 On 30.08.2015 17:37, bartekltg wrote: > One example is when we do not need a frequent small resizing, > and want to keep additional memory usage low. OK, it is not that bad, at least in gcc. int main() { const int N = 1025; vector<int> A(N,0), B,C,D; B.resize(N); D.reserve(N); cout<<A.capacity()<<" "<<B.capacity()<<" "<<C.capacity()<<" "<<D.capacity()<<endl; for (int i=0;i<N;i++) { A[i]=i; B[i]=i; C.push_back(i); D.push_back(i); } cout<<A.capacity()<<" "<<B.capacity()<<" "<<C.capacity()<<" "<<D.capacity()<<endl; A.push_back(0); cout<<A.capacity()<<endl; return 0; } output: 1025 1025 0 1025 1025 1025 2048 1025 2050 Constructing, resizing ad reserving do not grab additional memory. bartekltg |
jt@toerring.de (Jens Thoms Toerring): Aug 30 08:21PM > > instead of using containers. > yes, and using possible delete as well (or if smar pointers, then > reset). so total management Note: if you've a smart pointer you mat not have to do a reset() on it - if it goes out of scope (in the case of unique_ptr) - or the last instance holding a pointer to the memory (for shared_ptr) - the memory is deallocated automa- tically - the reset() is part of the smart pointers destruc- tion. Now, about the usefulness of new/delete: I think it depends a bit on what you're doing. Some of the stuff I do is inter- facing external devices used in physics and chemistry labs, and there you often have to fetch lots of data (think, for example, a trace from an oscilloscope which, with modern devices, can consist of hundreds of MBs of data). Now, at a low level you must use system functions like read() that expect a buffer the data get read into. Of course, you could create a local buffer large enough, read the data into it and then copy them all over to a vector. But that would at least double the memory used (at least temporarily) and would use up some extra time. And what you then typically do with the data doesn't require any of the bells and whistles a vector comes with - often it is nothing more exciting than writing them to a file. So it's simply more efficient not to use an extra array but an allocated buffer that one deletes once the data are safely on the disk. It would be different if one would be able to write directly to the vectors memory area and change it's size afterwards, but that's not allowed. So I'd say that vectors tend to be the best choice when you have something that often grows and shrinks but when all you need is some temporary (but not local to a single function or method) buffer which doesn't change in size an allocated array will do as well and, in a number of situations, even better. An alternative in such situations might seem to be a std::array, but there's the problem that you know the required size only in the method that "talks" to the device (which will tell you how many data it's got for you). And this makes it, as far as I can see, impossible to get it (the array) out of this method since the size is an essential part of the std::array you've got to specify it in either the return value type or for an argument of the method. Also template "magic" won't help since the size isn't something known at compile time. But perhaps someone else here has a clever solution for this... Regards, Jens -- \ Jens Thoms Toerring ___ jt@toerring.de \__________________________ http://toerring.de |
BV BV <bv8bv8bv8@gmail.com>: Aug 30 11:49AM -0700 The Story of Jesus and Mary in the Holy Quran (part 1 of 3): Mary Description: The following three part series consists entirely of verses from the Holy Quran about Mary (Mother of Jesus) including her birth, childhood, personal qualities, and the miraculous birth of Jesus. The Birth of Mary ndeed God chose Adam, Noah, the family of Abraham and the family of Imran over the worlds. An offspring, like one another (in righteousness). And God is All-Hearing, All-Knowing. (And mention) when the wife of Imran said, 'O my Lord, I have vowed to You what is in my womb, to be dedicated (to Your service), so accept this from me. Indeed, You are All-Hearing, All-Knowing.' Then when she delivered her (Mary), she said, 'O my Lord, I have delivered a female,' and God knew best what she delivered, 'And the male is not like the female, and I have named her Mary, and I seek refuge with You for her and for her children from Satan, the expelled (from the mercy of God).'" (Quran 3:33-36) The Childhood of Mary "So her Lord fully accepted her, and gave her a good upbringing, and put her under the care of Zechariah. Every time Zechariah entered upon her in the prayer room, he found her supplied with food. He said, 'O Mary, where do you get this from?' She said, 'This is from God. Indeed, God provides for whom He wills, without limit.'" (Quran 3:37) Mary, the Devout "And (mention) when the angels said, 'O Mary, indeed God has chosen you, purified you, and chosen you above the women of the worlds.' 'O Mary, be devoutly obedient to your Lord and prostrate and bow down along those who bow down (in prayer).' This is a part of the news of the unseen, which We reveal to you (O Muhammad). You were not with them when they cast lots with their pens to (decide) which of them should take care of Mary, nor were you with them when they disputed." (Quran 3:42-44) The Good news of a new-born child "(And mention) when the angels said, 'O Mary, indeed God gives you the good news of a word from Him, whose name will be the Messiah Jesus, the son of Mary, held in honor in this world and in the Hereafter, and of those who are near to God.' 'He will speak to the people in the cradle, and in old age, and he will be of the righteous.' She said, 'My Lord, how can I have a son when no man has touched me.' He said, 'So (it will be,) for God creates what He wants. When He decides something, He only says to it, 'Be,' and it is. And He will teach him the Book and wisdom and the Torah and the Gospel. And (will make him) a messenger to the Children of Israel (saying), 'Indeed I have come to you with a sign from your Lord. I make for you out of clay the likeness of a bird, then breathe into it, and it becomes a bird by the permission of God. And I heal the blind and the leper, and I bring the dead to life by the permission of God. And I inform you of what you eat and what you store in your houses. Surely, there is a sign for you in that, if you are believers. And (I have come) confirming the Torah that was (revealed) before me, and to allow you some of what was forbidden to you. And I have come to you with a proof from your Lord, so fear God and obey me. Indeed, God is my Lord and your Lord, so worship Him. This is the straight path." (Quran 3:45-51) "And mention in the Book (the story of) Mary, when she withdrew from her family to an eastern place. And she placed a screen to seclude herself from them. Then We sent to her Our angel (Gabriel), and he took the form of a well-created man before her. She said, "Indeed I seek refuge with the Most Merciful from you, if you do fear God."[1] (The angel) said, 'I am only the messenger of your Lord to give to you (the news of) a pure boy.' She said, 'How can I have a son, when no man has touched me (in marriage), and I am not a prostitute?' He said, So your Lord said, 'It is easy for Me. And We will make him a sign to people and a mercy from Us. And it is a matter (already) decided.'"[2](Quran 19:16-21) The Immaculate Conception "And she who guarded her chastity, so We breathed (a spirit) into her through Our angel, and We made her and her son (Jesus) a sign for the worlds."[3] (Quran 21:91) The Birth of Jesus "So she conceived him, and she withdrew with him to a remote place. And the pains of childbirth drove her to the trunk of a palm tree. She said, 'I wish I had died before this, and had been long forgotten. [Mary was worried that people would think badly of her as she was not married.] Then (baby Jesus) called her from below her, saying, 'Don't be sad. Your Lord has provided a stream under you.' Shake the trunk of the palm tree towards you, and it will drop on you fresh ripe dates. So eat and drink and be happy. And if you see any human, then say, 'Indeed I have vowed a fast to the Most Merciful so I will not speak to any human today.' Then she carried him and brought him to her people. They said, 'O Mary, indeed you have done a great evil.' 'O sister of Aaron, your father was not an evil man, and your mother was not a fornicator.' So she pointed to him. They said, 'How can we speak to a child in the cradle?' (Jesus) said, 'Indeed, I am a slave of God. He has given me the Scripture and made me a prophet.[4] And He has made me blessed wherever I may be, and He has enjoined on me prayer and charity as long as I remain alive. And (has made) me kind to my mother, and did not make me arrogant or miserable. And peace be upon me the day I was born, and the day I will die, and the day I will be raised alive.'" (Quran 19:22-33) "Indeed, Jesus is like Adam in front of God. He created him from dust, then said to him, 'Be,' and he was."[5] (Quran 3:59) "And We made the son of Mary and his mother a sign, And We gave them refuge and rest on a high ground with flowing water."[6] (Quran 23:50) The Excellence of Mary "And God gives as an example for those who believe, the wife of Pharaoh, when she said, 'My Lord, build for me a home near You in paradise, and save me from Pharaoh and his deeds, and save me from the wrongdoing people.' And (the example of) Mary, the daughter of Imran, who guarded her chastity, so We blew (the spirit of Jesus) into her through Our angel (Gabriel). And she believed in the words of her Lord, and His scriptures, and she was of the devout ones." (Quran 66:11-12) Footnotes: [1] The Most Merciful is one of the names of God in the Quran. [2] Jesus is a sign of God's power, where God showed people that He could create Jesus without a father, as He created Adam without any parents. Jesus is also a sign that God is well able to resurrect all people after their death, since the one who creates from nothing is quite able to bring back to life. He is also a sign of the Day of Judgment, when he returns to the earth and slays the Anti-Christ in the End Times. [3] Similarly, just as God created Adam with no father or mother, Jesus' birth was from mother with no father. All that is needed for God for something to happen is to say "Be" and it is; for God is capable of all things. [4] Prophethood is the highest and most honorable position a human can reach. A prophet is one who receives revelations from God through Angel Gabriel. [5] Adam was created when God said, "Be," and he to be without a father or a mother. And so was Jesus created by the Word of God. If the unusual birth of Jesus makes him divine, then Adam deserves more of that divinity because Jesus at least had one parent, while Adam had none. As Adam is not divine, so is Jesus not divine, but both are humble servants of God. [6] This is where Mary gave birth to Jesus. ======================================================= Jesus the Prophet "Say, 'We believe in God and what has been revealed to us and what has been revealed to Abraham, Ishmael, Isaac, Jacob, and to the prophet-descendants (of Jacob), and what has been given to Moses and Jesus, and what has been given to the prophets from their Lord. We make no distinction between any of them, and we are Muslims (in submission) to Him.'" (Quran 2:136) "Indeed, We have revealed to you (O Muhammad) as We revealed to Noah and the prophets after him. And We revealed to Abraham, Ishmael, Isaac, Jacob, and the prophet-descendants (of Jacob), Jesus, Job, Jonah, Aaron, and Solomon, and We gave the book to David." (Quran 4:163) "The Messiah son of Mary was only a messenger (like other) messengers that had passed away before him. And his mother was a strong believer.[1] They both used to eat food.[2] Look how We make the proofs clear to them, then look how they (disbelievers) turn away." (Quran 5:75) "He (Jesus) was only a servant whom We have favored, and We made him an example to the Children of Israel." (Quran 43:59) The Message of Jesus "And in their (the prophets') footsteps, We sent Jesus the son of Mary, affirming the Torah that had come before him. And We gave him the Gospel, in it was guidance and light, affirming the Torah that had come before it, and a guidance and an admonition for the pious." (Quran 5:46) "O people of the Scripture, do not go to extremes in your religion, and do not say about God except the truth. The Messiah Jesus, son of Mary, is only a messenger from God and a word from Him ("Be" and it is), which He sent to Mary, and a soul from Him.[3] So, believe in God and His messengers, and do not say, "Three." Stop, it is better for you. Indeed, God is one; exalted is He above having a son. To Him belongs whatever is in the heavens and whatever is on the earth. And God is sufficient as a Determiner of all affairs. Never would the Messiah look down upon being a worshipper of God, nor would the angels who are close (to God).[4] And whoever looks down upon the worship of God and is arrogant, then He will gather them to Himself all together." (Quran 4:171-172) "This is Jesus, the son of Mary. And this is the statement of truth, which they doubt. It is not possible for God to take a son. Far is He above this! When He decides something, He just says to it, "Be," and it is.[5] (Jesus said), 'And indeed God is my Lord and your Lord, so worship Him. That is a straight path.' But the sects disagreed (over the straight path), so woe to the disbelievers from meeting a horrible Day." (Quran 19:34-37) "And when Jesus came with clear proofs, he said, 'I have come to you with prophethood, and to make clear to you some of what you disagree about, so fear God and obey me. Indeed, God is my Lord and your Lord, so worship Him. This is a straight path.' But the groups disagreed among themselves (about the message of Jesus), so woe to those who disbelieved from the punishment of a painful Day." (Quran 43:63-65) "And (remember) when Jesus, son of Mary, said, "O Children of Israel, I am the messenger of God to you confirming the Torah that came before me, and bringing good news of a messenger that will come after me, whose name will be Ahmad.[6] But when he came to them with clear proofs, they said, "This is clear magic."[7] (Quran 61:6) The Miracles of Jesus "So she pointed to him. They said, 'How can we speak to a child in the cradle?' (Jesus) said, 'Indeed, I am a servant of God. He has given me the Scripture and made me a prophet.[8] And He has made me blessed wherever I am, and has commanded me to me pray and give charity as long as I remain alive. And (has made) me kind to my mother, and did not make me arrogant or miserable. And peace be upon me the day I was born, and the day I will die, and the day I will be raised alive.'" (Quran 19:29-33) (More miracles have been mentioned under: The Good news of a new-born child) The Table Spread (of food) from Heaven by God's Permission "(And) when the disciples said, 'O Jesus, son of Mary, will your Lord send down to us a table spread (with food) from heaven?' He said, 'Fear God, if you are indeed believers.' They said, 'We wish to eat from it and have our hearts be reassured, and to know that you have indeed told us the truth and that we be witnesses to it.' Jesus the son of Mary said, 'O God, our Lord, send us from heaven a table spread (with food) to be for us a festival for the first of us and the last of us and a sign from You. And provide for us, You are the Best of providers.' God said, 'I am going to send it down to you, but if any of you after that disbelieves, then I will punish him with a punishment such as I will not put on anyone else.'" (Quran 5:112-115) Jesus and His Disciples "O you who believe, champion God's (religion), like when Jesus son of Mary said to the disciples, 'Who will champion God's (religion) with me?' The disciples said, 'We are the champions of God's (religion).' Then a group of the Children of Israel believed and a group disbelieved. So We supported those who believed against their enemy, and they became victorious."[9] (Quran 61:14) "And when I inspired the disciples to believe in Me and My messenger, so they said, 'We believe, and bear witness that we are Muslims (in submission to God).'" (Quran 5:111) "Then We sent after them Our messengers, and We sent Jesus -son of Mary, and gave him the Gospel. And We put in the hearts of those who followed him compassion and mercy. But We did not command monasticism, rather they invented it for themselves to please God with it, yet they did not observe it as it should be observed. So We gave those who believed among them their reward, but many of them are disobedient." O you who believe, fear God and believe in His messenger, He will then give you a double portion of His mercy, and give you light by which you can walk, and He will forgive you. And God is Most Forgiving, Most Merciful. (This We say) so that the people of the Scripture may know that they have no control over God's favor, and that (His) favor is in His Hand to give it to whomever He wills. And God is the Owner of great bounty."[10] (Quran 57:27-29) Footnotes: [1] The Arabic word here indicates the highest level of faith possible, where the only one higher is prophethood. [2] Both the Messiah and his pious mother used to eat, and that is not a characteristic of God, who does not eat nor drink. Also, the one who eats defecates, and this cannot be an attribute of God. Jesus here is likened to all the noble messengers that had preceded him: their message was the same, and their status as non-divine creatures of God is similar. The highest honor that can be afforded to a human is prophethood, and Jesus is one of the five highly regarded prophets. See verse 33:7 & 42:13 [3] Jesus is called a word or a soul from God because he was created when God said, "Be," and he was. In that he is special, because all humans, except Adam and Eve, are created from two parents. But despite his uniqueness, Jesus is like everyone else in that he is not divine, but a mortal creature. [4] Everything and everyone else other than God is a worshipper or a slave of God. The verse is asserting that the Messiah would never claim a status above that of a worshipper of God, dismissing any claim to the contrary of his divinity. And indeed he would never disdain such a position, because this is the highest honor any human can aspire to. [5] If the creation of Jesus without a father makes him the son of God, then everything created like Jesus without a predecessor should be divine too, and that includes Adam, Eve, the first animals, and this whole earth with its mountains and waters. But Jesus was created like all things on this earth, when God said, "Be," and he was. [6] This is another name of Prophet Muhammad. [7] This can refer to both prophets, Jesus and Muhammad, peace be upon them. When they came with the message from God to their people, they were accused of bringing magic. [8] Prophethood is the highest and most honorable position a human can reach. A prophet is one who receives revelations from God |
ram@zedat.fu-berlin.de (Stefan Ram): Aug 30 12:53PM >Short answer: what would you have a smart pointer hold but >a pointer to allocated memory (typically allocated with >'new')? A pointer to allocated memory, typically allocated with a make function. auto object = ::std::make_unique< A >( args ); |
ram@zedat.fu-berlin.de (Stefan Ram): Aug 30 02:55PM >I understand that OP ask about 'a normal user' should >use news, not someone who write standard library. When Stroustrup teaches C++, he shows us how to implement a Vector class early (at about 4% of the book) in his book »The C++ programming language«. |
ram@zedat.fu-berlin.de (Stefan Ram): Aug 30 04:49PM >Exactly. Either no exceptions allowed or some sort of translation is in >place with possible constraints. Microsoft already has thought about this: Letting a C++ or Win32 structured exception escape a COM method is illegal. All such exceptions must be caught and turned into appropriate HRESULTs. For more information on this topic, see »Effective COM« (Addison-Wesley, 1998), by Don Box, Keith Brown, Tim Ewald, and Chris Sells. |
bleachbot <bleachbot@httrack.com>: Aug 30 08:49PM +0200 |
Robert Wessel <robertwessel2@yahoo.com>: Aug 30 12:01AM -0500 On Sat, 29 Aug 2015 09:36:35 -0700 (PDT), 嘱 Tiib <ootiib@hot.ee> wrote: >to adjust translation mechanisms to/from alien exceptions at interface >border but I would hate '__try<"Ada">' garbage keywords all over the code >or the like. It is just pure ugliness for me ... YMMV. Until recently, threads were "alien" to C and C++. Perhaps those should not have been exposed to C or C++ programs on platforms that support threads? |
Richard Damon <Richard@Damon-Family.org>: Aug 30 09:00AM -0400 On 8/29/15 8:46 AM, Öö Tiib wrote: > allowed implicitly (as by default) to be passed to caller of > extern "C" function over supposedly C interface since there is > 'noexcept' now in language. The problem with this is that extern "C" functions are NOT controlled by the C standard, but the C++ standard. It is the C++ standard that defines the construct extern "xxx", and the meaning of it. It gives as a purpose the interfacing to code using an "ABI" possibly different than the one used by the C++ implementation. The standard provides little requirements on these ABIs other than that the implementation must document what ABIs it supports (and thus indirectly the ABIs themselves, although that documentation may just be a pointer to the ABI documentation) and a requirement that extern "C" be one of the syntactically valid options. The only code that is required to be able to call via extern "C" is a function compiled in C++ with the extern "C" calling convention. There is no requirement that an actually C implementation exists with that ABI. Normally there is, as most C++ compilers can also be put into a "C" mode (since C is largely a subset of C++, especially if you are only supporting older C standards). It is quite possible for the "C" abi (or any other "XXX" abi) to be defined in a way that is compatible with passing C++ exceptions. This says that exceptions through C code aren't just "undefined behavior" but it is implement defined whether passing exceptions is defined behavior. It would be presumptive of the C++ standard to say that it is "improper" to allow exceptions over the implementation defined ABI called "C". We also have the specter of backwards compatibility. Standards Committees take a hard look at changing things that break backwards compatibility, especially quietly. Since prior to adding noexcept to the language, it was quite possible to have extern "C" functions that did throw exceptions, to silently change this so that such a function becomes undiagnosed undefined behavior (undiagnosed as there is fundamentally no way to know if a given extern "C" will throw or not, one of the reasons to add noexcept to the language) would be a quiet breaking change, something the committee tries hard not to do. This is basically the same reason noexcept isn't the default on C++ functions too. > implementation has to define what it does. I would only like that it > was *required* from implementations not to "forget" that exceptions > are part of interface. extern "C" is just as implementation defined, the only difference is that extern "C" is mandated to exist, as opposed to its existence also being implementation defined. > differ. So if C++ implemention declares that it can provide > extern "Ada" interface then I would expect either only Ada > exceptions from it or no exceptions at all. If C++ can call Ada, then Ada can call C++ by defining a function as extern "Ada", thus the implementation needs to define how exceptions cross the boundary (or that they can't). It may well be that some form of mapping will occur so that each can understand the others exceptions (or it doesn't make much sense to allow it). |
"Öö Tiib" <ootiib@hot.ee>: Aug 30 07:52AM -0700 > Until recently, threads were "alien" to C and C++. Perhaps those > should not have been exposed to C or C++ programs on platforms that > support threads? Perhaps you did not read what I wrote, (sorry if it was too long for you) and formed instead some sort of strawman inside of your head about my position. I am puzzled what have threads to do with alien kinds of exceptions. Threads are same for all languages and are not part of interface between subroutines so those were just regulated by other standards until recently. Exceptions are different between languages and are part of interface between subroutines. So how those are dealt with is responsibility of inter-language interface. On case of C++ that has been 'extern "OtherLanguage"' since before its very standardization. What is the connection here? |
"Öö Tiib" <ootiib@hot.ee>: Aug 30 09:32AM -0700 On Sunday, 30 August 2015 16:01:06 UTC+3, Richard Damon wrote: > The problem with this is that extern "C" functions are NOT controlled by > the C standard, but the C++ standard. It is the C++ standard that > defines the construct extern "xxx", and the meaning of it. Indeed and my position is that it does that weakly about extern "C". That is bad because majority of pain in C++ is it containing duplicated set of features for to be "backward compatible" with C. C with what C++ can't interface decently. Rest of extern "xxx" are implementation defined anyway. > implementation exists with that ABI. Normally there is, as most C++ > compilers can also be put into a "C" mode (since C is largely a subset > of C++, especially if you are only supporting older C standards). Yes and exceptions are exactly a part of subroutine call interface, IOW that ABI. So how exceptions behave must be defined by the one who defines the requirements for it. Should C++ standard be made by software analysts and architects (who try to be clear and explicit) or by language lawyers (who try to be verbose and vague)? > It is quite possible for the "C" abi (or any other "XXX" abi) to be > defined in a way that is compatible with passing C++ exceptions. Where can I possibly claim that interface specification is impossible task? Exceptions are not more special than any other part of interface. C++ has chosen to raise arbitrary C++ objects as exceptions. The extern "C" function has limitations about parameters but none about exceptions. Isn't it just work not done? > fundamentally no way to know if a given extern "C" will throw or not, > one of the reasons to add noexcept to the language) would be a quiet > breaking change, something the committee tries hard not to do. It is perhaps correct about C++ that exceptions have never been thought out properly. What we need is still a tool with what the things can be possibly made nicely in the future. If it is too risky then add extern "C ABI" or whatever and deprecate extern "C" (with diagnostic required), suits me. > This is basically the same reason noexcept isn't the default on C++ > functions too. Latter is still OK since lot of people use standard library in majority of their code and it does throw occasionally. We may need to avoid standard library in embedded system but there we turn exceptions usually off anyway. > cross the boundary (or that they can't). It may well be that some form > of mapping will occur so that each can understand the others exceptions > (or it doesn't make much sense to allow it). Exactly. Either no exceptions allowed or some sort of translation is in place with possible constraints. What we have now is where exceptions just maybe fly or maybe don't fly and there are no restrictions to their binary nature. Also I don't like what "implementation defined" means in C++. If something is "implementation defined" then please make special standardized traits available so our code can also find out compile time how implementation did define it. |
David Brown <david.brown@hesbynett.no>: Aug 30 04:22PM +0200 On 29/08/15 19:17, Prroffessorr Fir Kenobi wrote: >>> c:\mingw\bin\g++ -std=c++98 -O2 -c -w test7.c -fno-rtti >>> -fno-exceptions -fno-threadsafe-statics -march=core2 >>> -mtune=generic -mfpmath=both -msse2 Why are you using "-mtune=generic" ? Here you are telling gcc that the code will always run on a "core2" machine (with -march=core2), yet it should (with "-mtune=generic") make code that runs reasonably on any x86. Instead, you want "-march=native" for best performance - this tells the compiler that it can use anything supported by the current processor, and should optimise code to run on exactly that system. You only need other flags if you are trying to make binaries that run fast on a range of different x86 systems - but here your main aim is speed on your own system. And you don't want to use flags like "-mfpmath=both" or "-msse2" - use "-march=native" and let the compiler do the best job, as it already knows what extensions your cpu supports. If your code has any floating point, and you don't need absolute conformance to the IEEE rules (few programs need that), then use "-ffast-math" to allow the compiler greater freedom in maths optimisations. >>> not a difference) >> OK, I'm not familiar with that compiler. But is O2 really the >> highest level? GCC and Clang both have O3. mingw is gcc on Windows. >> Andy > -O3 may produce unstable code which has risky optimisations and > sometimes even crashes.. here i tested and O3 makes slower code -O3 should not ever produce "risky" optimisations or code that crashes because of optimisations. If your code crashes with -O3 but not with -O2, then either your code has bugs or the compiler has bugs. Almost certainly it is the former, especially when you are mixing in inline assembly. But if you think it is a real gcc bug, then the gcc folk would love to know about it. There are sometimes optimisations that are experimental or known to cause problems - these are clearly marked in the documentation for that release of gcc, and always require specific flags (they are never part of any -O flag). On the other hand, it is well-known that -O3 does not necessarily lead to faster code than -O2. It depends very much on the circumstances and the code in question, as well as the processor in use. For example, -O3 is more aggressive about loop unrolling - cache effects and a good branch predictor may mean that an unrolled loop is actually slower than the rolled loop. Some trial and error here is worth the effort for best code, and you might have fun playing with other options in: <https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html> You can even change the optimisation levels on different functions, at least in newer gcc. |
Nobody <nobody@nowhere.invalid>: Aug 30 12:57AM +0100 On Sat, 29 Aug 2015 15:38:01 +0000, Laszlo Lebrun wrote: > Does a library exist to simulate a serial COM port? Is that accessible to > a technically oriented noob within a few weeks? Two USB-serial converters and a null-modem cable? |
Nobody <nobody@nowhere.invalid>: Aug 30 12:53AM +0100 On Sat, 29 Aug 2015 01:12:18 -0700, Prroffessorr Fir Kenobi wrote: > what could i do copmare two exe smaller and biger by some binary diff? > disasemble and compare for differences? "objdump -h ..." will show the sizes of the individual sections. |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment