Wheels-Of-Fire

Forum Replies Created

Viewing 20 posts - 181 through 200 (of 1,996 total)
  • Author
    Posts
  • in reply to: C++ Programming #65580
    Wheels-Of-FireWheels-Of-Fire
    Participant
      @grahamdearsley
      Forumite Points: 4

      I have just read something else about iterators and some interesting stuff about the built in array type. I am not sure if the following is how it always was under C but this is what happens with C++.

      The first thing is that the compiler usually treats the name of an array as a pointer to the first element of the array so it is of type pointer rather than an array type so I can do the following:

      string nums [] = {“one”, “two”, “three”};

      string *ptr = nums;

      Notice I did not need the “&”, address of, operator in front of nums because nums is already a pointer and it refers to the value “one”.

      The next thing of note is that pointers to array elements are treated like iterators so if I do this:

      ++ptr1;

      ptr1 now refers to the second element in the array and the value “two”.

      The third thing of note is that arrays are built in types rather than classes so they don’t have the .begin() and .end() functions that C++ containers do. To get around this potential problem, C++11 provides a new class header in the standard library called “iterator” and it contains the .begin() and .end() functions for built in arrays. I can use those functions to get pointers to the first and last elements of an array as follows:

      string *beg = begin(ptr1);

      string *end = end(ptr1);

      Those pointers can now be used in the same way as an iterator would be to access members of the array and iterator arithmetic applies.

      in reply to: C++ Programming #65539
      Wheels-Of-FireWheels-Of-Fire
      Participant
        @grahamdearsley
        Forumite Points: 4

        The container iterators do indeed provide similar functionality to a doubly linked list but the way things are organised in memory are different. The elements of a doubly linked list contain their data and pointers to the location of the previous and next member of the list (as you no doubt know) so the members of the list can be anywhere in memory, the compiler only needs to keep track of the first element to find all the rest.

        The thing with a container is that it does NOT store its data in the index list (except for C++ style strings which DO. Storing an index pointer to a single byte would be silly :wacko: ). The indexes of a container just point at the data they represent, they are strictly “vectors” to the data rather than pointers but the idea is the same. The upshot is that the data can be anywhere in memory

        Container indexes are always the size of a vector, no matter what the size of the data type, and they are always stored contiguously in memory so there is no need for them to hold the address of the previous or next index, they are always previous or next in memory. Again the compiler only needs to keep track of the first element to find the rest.

        The indexes of a container MUST move to a bigger memory block if a container is expanded because the indexes must remain contiguous and you cant just tack a new index on the end, who knows what that memory may belong to ?

        The main point of a container is that it is quick to expand because only the indexes have to move, the data stays put. If you want to stop your indexes from moving, and you know the maximum size of your container in advance, you can use the .reserve(n) member function that C++ container classes provide. The .reserve(n) function reserves a set number of indexes but it does not set a limit so your indexes will only stay put as long as your container doesn’t expand past that number.

        As for hashed iterators ? I don’t know yet, my book covers them in more detail in about 400 pages time :unsure:

        in reply to: C++ Programming #65525
        Wheels-Of-FireWheels-Of-Fire
        Participant
          @grahamdearsley
          Forumite Points: 4

          I meant the type of b and e of course :wacko:

          in reply to: C++ Programming #65523
          Wheels-Of-FireWheels-Of-Fire
          Participant
            @grahamdearsley
            Forumite Points: 4

            I have been looking again at C++ Container iterators and I think I finally get it. Here is my understanding of them.

            Every C++ library container class (vector, string, etc)  provides a special type of reference called an iterator. Every container class has the member functions .begin() and .end() that can be used to obtain an iterator to the first and one past the last element of a container like so, for vector v:

            auto b = v.begin(), e = v.end();

            I used “auto” above because the type of a and b is “iterator” and each container defines its own iterator type within its own namespace and its not often important to know what the exact type is. Iterators are objects (like pointers) so if you really must create an empty iterator then you can create one called “it” like this:

            vector<int> :: iterator it;

            Like with pointers it is possible to dereference an iterator to obtain the object it references.

            The main use for iterators is to iterate over the elements of a container (Not really a surprise !) so they support ++ and –. If you inc or dec an iterator you do NOT inc/dec its value, you inc/dec the container index it refers to.

             

            in reply to: C++ Programming #65408
            Wheels-Of-FireWheels-Of-Fire
            Participant
              @grahamdearsley
              Forumite Points: 4

              They are much worse than unfriendly, they are mostly dim and self important too :negative:

              I haven’t asked a question on there for ages but I sometimes answer them. For which I get abuse about not following the house style and threats of having my answer removed, followed by a load of up votes from people who were helped by my answer :mail:

              Really, a lot of them just seem to like the look of their name in print. Its not so bad on the C++ tag but some  of the replies on the Java tag are pure drivel.

              in reply to: C++ Programming #65259
              Wheels-Of-FireWheels-Of-Fire
              Participant
                @grahamdearsley
                Forumite Points: 4

                I just found something that Visual Studio Intellisense doesn’t spot.

                If I create a vector like so :

                vector<int> v1 {1, 2, 3};

                Then I get a vector with three int elements, as is normal. If I then create a pointer to the 2nd element (unwise ) like this:

                Int* ptrv1 = &v1[1];

                Thats fine too. Now I can dereference ptrv1 and print its value, in this case 2, as follows:

                cout << *ptrv1;

                Works fine, but if I do this:

                v1.push_back(4);

                And then try to output the value of ptrv1 again, the program will compile but terminate with a memory access violation exception.

                The reason is I expanded the vector so all its indexes moved to a bigger memory block, making my pointer invalid.

                in reply to: C++ Programming #65148
                Wheels-Of-FireWheels-Of-Fire
                Participant
                  @grahamdearsley
                  Forumite Points: 4

                  Ooh, I have been promoted to Editor status on Stack Overflow.

                  Maybe NOW people on there will stop criticising my writing style and read the content.

                  Nah, never happen 🤣

                  in reply to: C++ Programming #64923
                  Wheels-Of-FireWheels-Of-Fire
                  Participant
                    @grahamdearsley
                    Forumite Points: 4

                    I have somehow managed to install CMAKE support in my Visual Studio GUI. Now when I hit File>Open I get the option to open a CMAKE file and if I do it only imports the files listed in there, instead of all the files in the current directory. Don’t know what I did but I wish I had done it before I went through putting all the project code from my C++ Primer book into separate folders :wacko:

                    in reply to: Missing Files #64907
                    Wheels-Of-FireWheels-Of-Fire
                    Participant
                      @grahamdearsley
                      Forumite Points: 4

                      A slight deviation, but still file and backup based.

                      I just noticed that the desktop I look at all day on my Surface pro 7 is actually C:\users\”Me”\Onedrive\desktop.

                      I had wondered how my desktop was getting backed up to Onedrive but I never really looked before.

                      in reply to: Seasons Greetings #64903
                      Wheels-Of-FireWheels-Of-Fire
                      Participant
                        @grahamdearsley
                        Forumite Points: 4

                        Merry Christmas

                        And a Brexit Deal New Year Ho Ho Ho 😉

                         

                        in reply to: C++ Programming #64875
                        Wheels-Of-FireWheels-Of-Fire
                        Participant
                          @grahamdearsley
                          Forumite Points: 4

                          Yay. I have finally got github properly setup and integrated with Visual Studio, only took 3 hours !

                          I can now clone a copy of any publicly avaliable repository to a local folder on MY machine, it doesn’t matter if they thought to include a master zip or not.

                          The first thing I did was to clone a copy of the Visual Studio package manager (vspkg)  package and get it properly installed and integrated into VS, I only had the package builder part previously.

                          Now I can get and run all the VS demo packages (the bullet physics demo looks good) along with all the VS extensions written by MS and others, should I wish 🙂

                          in reply to: Pancreatitis and a new diet. #64837
                          Wheels-Of-FireWheels-Of-Fire
                          Participant
                            @grahamdearsley
                            Forumite Points: 4

                            Good one Dave. LaLaLa La LaLa La and so on 🙂

                            in reply to: Pancreatitis and a new diet. #64833
                            Wheels-Of-FireWheels-Of-Fire
                            Participant
                              @grahamdearsley
                              Forumite Points: 4

                              Oh no they won’t !

                              I went for my 6 month routine blood test on monday and I just got a message from my Doctor (9.43 pm) saying my Potassium level is dangerously high at 6.1. He has booked me a retest at 7.30 am tomorrow in their emergency clinic but he says if I feel unwell then I should go to A&E immediately.

                              Well I do feel unwell but sod that for a game of soldiers, I will go for the test but I am NOT spending ANOTHER Christmas in hospital.

                              in reply to: C++ Programming #64829
                              Wheels-Of-FireWheels-Of-Fire
                              Participant
                                @grahamdearsley
                                Forumite Points: 4

                                At last, by special request, without further ado, I bring you :

                                The Visual Studio C++ Manual !!!

                                https://1drv.ms/b/s!ApY7Ke0brhrmgP8N77z7PjfE6NoINg?e=zpeYGj

                                Please download it before its gone 🙂

                                in reply to: CyberPunk 2077 #64730
                                Wheels-Of-FireWheels-Of-Fire
                                Participant
                                  @grahamdearsley
                                  Forumite Points: 4

                                  Optimizing for older hardware is not so simple because their code will have to interogate the hardware for its profile level and then supply different code to match. This is really like writing more than one version of the program.

                                  in reply to: CyberPunk 2077 #64728
                                  Wheels-Of-FireWheels-Of-Fire
                                  Participant
                                    @grahamdearsley
                                    Forumite Points: 4

                                    Yes I saw that, but I recon the biggest cause of slowdowns in cyberpunk is its use of “Groundbreaking”  new features that are not directly supported in older hardware. The rendering must fall back on software emulation routines provided by the API.

                                    in reply to: CyberPunk 2077 #64723
                                    Wheels-Of-FireWheels-Of-Fire
                                    Participant
                                      @grahamdearsley
                                      Forumite Points: 4

                                      I am not at all up on 3D rendering techniques but I did look into DX12 features a couple of months ago.

                                      A developer can target DX12 and the result will probably run on DX9c and above hardware but the Hardware Driver DX level profile will report which features are actually supported in hardware and any that aren’t will be emulated by software running on the CPU.

                                      Both the new consoles use graphics hardware based on the AMD Big Navi architecture and it provides hardware support for many more features, so if a game is using them it will run like a dog on older hardware.

                                      I believe that the Vulcan API behaves in a similar way but I haven’t looked.

                                      in reply to: C++ Programming #64700
                                      Wheels-Of-FireWheels-Of-Fire
                                      Participant
                                        @grahamdearsley
                                        Forumite Points: 4

                                        Ont of interest, the Visual Studio Visual XAML editor is Blend (not to be confused with Blender but it can do 3D objects and animations.

                                        Blend is a big upgrade over the Forms editor that was previously used with .NET languages and it loads by default when I start a C++/WinRT project.

                                        Blend opens in a split screen mode where the top half is a canvas where you can drag and drop objects and the bottom half shows the XAML code for the page.

                                        If you add or change objects on the canvas then it changes the code and vise versa.

                                        in reply to: step up transfomer #64677
                                        Wheels-Of-FireWheels-Of-Fire
                                        Participant
                                          @grahamdearsley
                                          Forumite Points: 4

                                          Sorry but Nah.

                                          Your router is configured via DHCP, not some mystical analogue pulse and the ip address it gives you is all your isp’s network needs to know to set your speed.

                                          An ADSL modem uses several dirrerent analogue carrier frequency’s to send data and the line is continually tested to see which frequency’s are working best at any moment but thats it for analogue.

                                          A fiber connection doesn’t use analogue at all.

                                          in reply to: SPDIF / OPTICAL IN PLAYBACK LINUX #64667
                                          Wheels-Of-FireWheels-Of-Fire
                                          Participant
                                            @grahamdearsley
                                            Forumite Points: 4

                                            Below is some info on PC audio streams that it took me ages to decipher.

                                            The intel HD audio hardware is contained in the PCH or newer ICH chips. The hardware consists of 4 or more DMA engines that can be configured for input or output and they read or write to a memory buffer that an App or the OS has to manage. Data to/from the DMA engines is connected to the Intel designed HD audio bus. The HD audio bus is designed to have audio end points (usually codec’s) connected to it, each with its own ID. I have never seen a motherboard that exposes the HD audio  bus to the outside world so the only device ever connected is the onboard codec.

                                            The Windows core audio subsystem has another way of generating audio streams which uses the CPU to read a buffer and then write the data out to any bus on the system, that’s how sound data gets delivered to USB and PCIe devices.

                                          Viewing 20 posts - 181 through 200 (of 1,996 total)