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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Memory function equivalent to that found in fread

Memory function equivalent to that found in fread

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
6 Posts 2 Posters 0 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.
  • A Offline
    A Offline
    alleyes 0
    wrote on last edited by
    #1

    I'm looking for a method that mimics the functionality of fread without a file pointer. I want to read from a buffer into a buffer, for a number of bytes and move the pointer to the source buffer by the number of bytes returned - like fread. Anyone done anything like this? Thanks in advance

    Jer 29:11

    _ 1 Reply Last reply
    0
    • A alleyes 0

      I'm looking for a method that mimics the functionality of fread without a file pointer. I want to read from a buffer into a buffer, for a number of bytes and move the pointer to the source buffer by the number of bytes returned - like fread. Anyone done anything like this? Thanks in advance

      Jer 29:11

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      BYTE* pDest = <Destination Buffer>;
      BYTE* pSrc = <Source Buffer>;
      SIZE_T size = <Size to Read>;

      MemoryRead(pDest, pSrc, size);

      SIZE_T MemoryRead(BYTE* pDest, BYTE* pSrc, SIZE_T size)
      {
      CopyMemory(pDest, pSrc, size);
      pSrc += size;

      return size;
      }

      «_Superman_» I love work. It gives me something to do between weekends.

      A 2 Replies Last reply
      0
      • _ _Superman_

        BYTE* pDest = <Destination Buffer>;
        BYTE* pSrc = <Source Buffer>;
        SIZE_T size = <Size to Read>;

        MemoryRead(pDest, pSrc, size);

        SIZE_T MemoryRead(BYTE* pDest, BYTE* pSrc, SIZE_T size)
        {
        CopyMemory(pDest, pSrc, size);
        pSrc += size;

        return size;
        }

        «_Superman_» I love work. It gives me something to do between weekends.

        A Offline
        A Offline
        alleyes 0
        wrote on last edited by
        #3

        Very cool and to the point. The key was to return the size - like fread. Thanks much :-D

        Jer 29:11

        1 Reply Last reply
        0
        • _ _Superman_

          BYTE* pDest = <Destination Buffer>;
          BYTE* pSrc = <Source Buffer>;
          SIZE_T size = <Size to Read>;

          MemoryRead(pDest, pSrc, size);

          SIZE_T MemoryRead(BYTE* pDest, BYTE* pSrc, SIZE_T size)
          {
          CopyMemory(pDest, pSrc, size);
          pSrc += size;

          return size;
          }

          «_Superman_» I love work. It gives me something to do between weekends.

          A Offline
          A Offline
          alleyes 0
          wrote on last edited by
          #4

          I spoke too soon! Actually, it doesn't quite work like fread. CopyMemory - defined as RtlCopyMemory needs size as an input. fread on the other hand returns the number of bytes read. Thanks for responding but I still don't have the solution.

          Jer 29:11

          _ 1 Reply Last reply
          0
          • A alleyes 0

            I spoke too soon! Actually, it doesn't quite work like fread. CopyMemory - defined as RtlCopyMemory needs size as an input. fread on the other hand returns the number of bytes read. Thanks for responding but I still don't have the solution.

            Jer 29:11

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            The reason is very clear. A file has an end and when you give a size, it will read either the mentioned size or till the end of the file. But a memory read either succeeds or fails.

            «_Superman_» I love work. It gives me something to do between weekends.

            A 1 Reply Last reply
            0
            • _ _Superman_

              The reason is very clear. A file has an end and when you give a size, it will read either the mentioned size or till the end of the file. But a memory read either succeeds or fails.

              «_Superman_» I love work. It gives me something to do between weekends.

              A Offline
              A Offline
              alleyes 0
              wrote on last edited by
              #6

              OK. I just thought that there was a solution -perhaps you did too. I guess there's no way to do this

              Jer 29:11

              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