Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to fetch values from memory using structure variable name.

How to fetch values from memory using structure variable name.

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialperformancehelp
14 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S shanmugarajaa

    For example: 1. x1[100] is the Struct variable which hold the value of 10 2. Now User gives the input as x1[100] in the given textbox. 3. My application need to fetch the value 10(for x1[100]) from the memory location and display value 10 to user.

    A Offline
    A Offline
    Albert Holguin
    wrote on last edited by
    #4

    there are multiple steps... which one do you need help with? ...for a user to point out a variable in an array, all you need to do is ask for the name of the array and the index... then look up the name or label against a set of valid labels, and use the index specified to grab the value.

    S 1 Reply Last reply
    0
    • A Albert Holguin

      there are multiple steps... which one do you need help with? ...for a user to point out a variable in an array, all you need to do is ask for the name of the array and the index... then look up the name or label against a set of valid labels, and use the index specified to grab the value.

      S Offline
      S Offline
      shanmugarajaa
      wrote on last edited by
      #5

      whether it is possible to calculate offset value? and Using offset, the struct variable value is fetched from the memory loaction.

      C 1 Reply Last reply
      0
      • S shanmugarajaa

        whether it is possible to calculate offset value? and Using offset, the struct variable value is fetched from the memory loaction.

        C Offline
        C Offline
        Chandrasekharan P
        wrote on last edited by
        #6

        Calculate Offset Value?? why?? Albert has given a very good suggestion. why not try that?

        Every new day is another chance to change your life.

        S 1 Reply Last reply
        0
        • C Chandrasekharan P

          Calculate Offset Value?? why?? Albert has given a very good suggestion. why not try that?

          Every new day is another chance to change your life.

          S Offline
          S Offline
          shanmugarajaa
          wrote on last edited by
          #7

          My senior engineer Implemented offset table procedure concept. Using offset table particular structure variable value is fetched from memory location and whenever structure get updated or modified then obviously offset table get modified or changed.Now days it became big problem for us. my question is whether albert idea is effect than this offset table procedure or any other suggestion is there to implement.

          A 1 Reply Last reply
          0
          • S shanmugarajaa

            my application consists of structure with 200 member variable.

            For Example: Struct sample { char xyz[200]; int x1[400]; char y2[100][10]; float z2[200]; ................... ................. .................. ................ } Now user will just passes the value like xyz[100], x1[201] and my application need to fetch the corresponding value from memory and display to them kindly help me friends..

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #8

            shanmugarajaa wrote:

            my application consists of structure with 200 member variable.

            Uhm... Is that really needed?

            Veni, vidi, vici.

            In testa che avete, signor di Ceprano?

            S 1 Reply Last reply
            0
            • CPalliniC CPallini

              shanmugarajaa wrote:

              my application consists of structure with 200 member variable.

              Uhm... Is that really needed?

              Veni, vidi, vici.

              S Offline
              S Offline
              shanmugarajaa
              wrote on last edited by
              #9

              Long year ago my senior engineers designed like that and i can't change those things. now my aim is to findout new way to get value for those structure variable without using offset table... any other choice is there?

              1 Reply Last reply
              0
              • S shanmugarajaa

                my application consists of structure with 200 member variable.

                For Example: Struct sample { char xyz[200]; int x1[400]; char y2[100][10]; float z2[200]; ................... ................. .................. ................ } Now user will just passes the value like xyz[100], x1[201] and my application need to fetch the corresponding value from memory and display to them kindly help me friends..

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #10

                200 member variables! Holy crap! Are they all named as badly as these? Just how is a user supposed to know the relevance of what IS stored at x1[100]? Apart from that, quite simply your app, which contains the struct instance, lets say it is called strinst, when asked for the value x1[100] just returns strint.x1[100], probably printfed into a string, for display.

                ============================== Nothing to say.

                S 1 Reply Last reply
                0
                • L Lost User

                  200 member variables! Holy crap! Are they all named as badly as these? Just how is a user supposed to know the relevance of what IS stored at x1[100]? Apart from that, quite simply your app, which contains the struct instance, lets say it is called strinst, when asked for the value x1[100] just returns strint.x1[100], probably printfed into a string, for display.

                  ============================== Nothing to say.

                  S Offline
                  S Offline
                  shanmugarajaa
                  wrote on last edited by
                  #11

                  But they are not created instant for an structure... instead of that they calculated offset value for each variable which is present in the structure. I dont know why they using such procedure...

                  L 1 Reply Last reply
                  0
                  • S shanmugarajaa

                    But they are not created instant for an structure... instead of that they calculated offset value for each variable which is present in the structure. I dont know why they using such procedure...

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #12

                    So you have the memory address, and you know the structure format, just cast the address to a struct pointer and access it as mystrinstptr->x1[100] If you dont have access to the memory you cant do anything.

                    ============================== Nothing to say.

                    1 Reply Last reply
                    0
                    • S shanmugarajaa

                      My senior engineer Implemented offset table procedure concept. Using offset table particular structure variable value is fetched from memory location and whenever structure get updated or modified then obviously offset table get modified or changed.Now days it became big problem for us. my question is whether albert idea is effect than this offset table procedure or any other suggestion is there to implement.

                      A Offline
                      A Offline
                      Albert Holguin
                      wrote on last edited by
                      #13

                      Using an offset value for this is just silly. There's no practical purpose and adds complexity with no benefit.

                      1 Reply Last reply
                      0
                      • S shanmugarajaa

                        my application consists of structure with 200 member variable.

                        For Example: Struct sample { char xyz[200]; int x1[400]; char y2[100][10]; float z2[200]; ................... ................. .................. ................ } Now user will just passes the value like xyz[100], x1[201] and my application need to fetch the corresponding value from memory and display to them kindly help me friends..

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #14

                        Hi, It sounds to me like you want to do this with the compiler preprocessor. Yes you can do this but it will be very ugly indeed. You will need to build the structs with #define statements and you can retrieve the member names with the #NAME directive[^]. You can get the offset to the struct members with the FIELD_OFFSET macro. Best Wishes, -David Delaune

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups