Loading ...
Sorry, an error occurred while loading the content.

When does BCX_TmpStr free memory?

Expand Messages
  • Ljubisa Knezevic
    I understand that BCX_TmpStr is a circular buffer. After it reaches 2048 it will start back at 0 and free that location. This part is OK. But when program is
    Message 1 of 10 , Aug 1, 2008
    View Source
    • 0 Attachment
      I understand that BCX_TmpStr is a circular buffer.
      After it reaches 2048 it will start back at 0 and free that location.
      This part is OK.

      But when program is about to finish, does it free memory or is this a
      memory leak?

      Ljubisa
    • Kevin Diggins
      ... It is freed by the operating system when the program exits.
      Message 2 of 10 , Aug 1, 2008
      View Source
      • 0 Attachment
        --- In BCX@yahoogroups.com, "Ljubisa Knezevic" <ljube@...> wrote:
        >
        > I understand that BCX_TmpStr is a circular buffer.
        > After it reaches 2048 it will start back at 0 and free that location.
        > This part is OK.
        >
        > But when program is about to finish, does it free memory or is this a
        > memory leak?
        >
        > Ljubisa
        >

        It is freed by the operating system when the program exits.
      • Ljubisa Knezevic
        ... I m not sure that I understand how this works. Local variable inside BCX_TmpStr: static char *StrFunc[2048]; Is a 2048 char pointers which gets allocated
        Message 3 of 10 , Aug 3, 2008
        View Source
        • 0 Attachment
          --- In BCX@yahoogroups.com, "Kevin Diggins" <ktdiggins@...> wrote:
          >
          > --- In BCX@yahoogroups.com, "Ljubisa Knezevic" <ljube@> wrote:
          > >
          > > I understand that BCX_TmpStr is a circular buffer.
          > > After it reaches 2048 it will start back at 0 and free that location.
          > > This part is OK.
          > >
          > > But when program is about to finish, does it free memory or is this a
          > > memory leak?
          > >
          > > Ljubisa
          > >
          >
          > It is freed by the operating system when the program exits.
          >
          I'm not sure that I understand how this works.

          Local variable inside BCX_TmpStr:
          static char *StrFunc[2048];

          Is a 2048 char pointers which gets allocated by calloc, right?

          But, shouldn't it be somehow freed by "free" function.

          In other situations if you don't call "free" for memory allocated by
          calloc, this is a mem leak.

          Why OS frees this memory, because it is local variable?


          Sorry for asking this but I still don't understand how this works.
        • Doyle Whisenant
          ... It s been my understanding that when *any* program exits, all of the memory was released back to the system. No matter how the memory was allocated. Of
          Message 4 of 10 , Aug 3, 2008
          View Source
          • 0 Attachment
            Ljubisa Knezevic wrote:
            > --- In BCX@yahoogroups.com, "Kevin Diggins" <ktdiggins@...> wrote:
            >
            >> --- In BCX@yahoogroups.com, "Ljubisa Knezevic" <ljube@> wrote:
            >>
            >>> I understand that BCX_TmpStr is a circular buffer.
            >>> After it reaches 2048 it will start back at 0 and free that location.
            >>> This part is OK.
            >>>
            >>> But when program is about to finish, does it free memory or is this a
            >>> memory leak?
            >>>
            >>> Ljubisa
            >>>
            >>>
            >> It is freed by the operating system when the program exits.
            >>
            >>
            > I'm not sure that I understand how this works.
            >
            > Local variable inside BCX_TmpStr:
            > static char *StrFunc[2048];
            >
            > Is a 2048 char pointers which gets allocated by calloc, right?
            >
            > But, shouldn't it be somehow freed by "free" function.
            >
            > In other situations if you don't call "free" for memory allocated by
            > calloc, this is a mem leak.
            >
            > Why OS frees this memory, because it is local variable?
            >
            >
            > Sorry for asking this but I still don't understand how this works.
            >
            >

            It's been my understanding that when *any* program exits, all of the
            memory was released back to the system. No matter how the memory was
            allocated. Of course, it wouldn't be the first time I was wrong. ;-)

            Doyle
          • Kevin Diggins
            ... If you are wrong, you have lots of company. It is my understanding that memory leaks occur within a running program and, if left unattended, the leak
            Message 5 of 10 , Aug 3, 2008
            View Source
            • 0 Attachment
              --- In BCX@yahoogroups.com, Doyle Whisenant <mekanixx@...> wrote:
              >
              > It's been my understanding that when *any* program exits, all of the
              > memory was released back to the system. No matter how the memory was
              > allocated. Of course, it wouldn't be the first time I was wrong. ;-)
              >
              > Doyle

              If you are wrong, you have lots of company.

              It is my understanding that memory leaks occur within a "running"
              program and, if left unattended, the leak will eventually crash the
              "running" program and sometimes even crash the operating system.

              Once the operating system is signaled that a program has terminated,
              the resources that the operating system allocated to the program at
              startup are recovered for re-use by the operating system.
            • Joe
              So, it would be a bad idea to repeated call certain BCX string functions in say handling WM_TIMER? ... the ... was ... wrong. ;-)
              Message 6 of 10 , Aug 3, 2008
              View Source
              • 0 Attachment
                So, it would be a bad idea to repeated call certain
                BCX string functions in say handling WM_TIMER?

                --- In BCX@yahoogroups.com, "Kevin Diggins" <ktdiggins@...> wrote:
                >
                > --- In BCX@yahoogroups.com, Doyle Whisenant <mekanixx@> wrote:
                > >
                > > It's been my understanding that when *any* program exits, all of
                the
                > > memory was released back to the system. No matter how the memory
                was
                > > allocated. Of course, it wouldn't be the first time I was
                wrong. ;-)
                > >
                > > Doyle
                >
                > If you are wrong, you have lots of company.
                >
                > It is my understanding that memory leaks occur within a "running"
                > program and, if left unattended, the leak will eventually crash the
                > "running" program and sometimes even crash the operating system.
                >
                > Once the operating system is signaled that a program has terminated,
                > the resources that the operating system allocated to the program at
                > startup are recovered for re-use by the operating system.
                >
              • Kevin Diggins
                ... Not necessarily, although if you are thinking of doing so, some spot checking of the results would be prudent.
                Message 7 of 10 , Aug 3, 2008
                View Source
                • 0 Attachment
                  --- In BCX@yahoogroups.com, "Joe" <yf777a@...> wrote:
                  >
                  > So, it would be a bad idea to repeated call certain
                  > BCX string functions in say handling WM_TIMER?

                  Not necessarily, although if you are thinking of doing so,
                  some spot checking of the results would be prudent.
                • Joe
                  I tried it before, and every few seconds 2k more would be allocated to my app. I did not let it run long enough, but if I read this thread correctly, if the
                  Message 8 of 10 , Aug 3, 2008
                  View Source
                  • 0 Attachment
                    I tried it before, and every few seconds 2k more would
                    be allocated to my app. I did not let it run long enough,
                    but if I read this thread correctly, if the app ran for
                    long enough, 2048*2048 would have eventually been allocated,
                    before the circular queue started at the beginning. I don't
                    remember the BCX string function, but when I saw the result
                    I decided to use sprintf as I have in the past. Probably not
                    enough from an efficency stand point.

                    I'd be willing to help add an option at the end of such string
                    functions, for a user supplied buffer... it would be less
                    BASIC, but only an option. There definately would be an
                    urgent warning in the help file regarding overflowing the
                    user supplied buffer. As a sometimes 'c' programmer I never
                    did such a thing ;-) ---- sure sure.

                    I think the overall efficency it some instances would be
                    worth using such an option. Maybe the effort and overhead
                    is not worth it. I once thought of maintaining my own BCX,
                    with things such as this, but it would be difficult to merge
                    and maintain with the main BCX; and doubt I would have the
                    time. But since I started dabbling in BCX 5 years ago, BCX
                    makes it easy to drop down to c. Overall, BCX makes coding
                    much easier than c. From what I have read you have had a
                    few to several programmers make a great set of tools.

                    -Joe

                    --- In BCX@yahoogroups.com, "Kevin Diggins" <ktdiggins@...> wrote:
                    >
                    > --- In BCX@yahoogroups.com, "Joe" <yf777a@> wrote:
                    > >
                    > > So, it would be a bad idea to repeated call certain
                    > > BCX string functions in say handling WM_TIMER?
                    >
                    > Not necessarily, although if you are thinking of doing so,
                    > some spot checking of the results would be prudent.
                    >
                  • Joe
                    never mind... my case was probably bad coding.... probably a lot of string$ + string2$ + str$(x) + ... I bet the function using would have solved it.
                    Message 9 of 10 , Aug 3, 2008
                    View Source
                    • 0 Attachment
                      never mind...

                      my case was probably bad coding....

                      probably a lot of string$ + string2$ + str$(x) + ...

                      I bet the function 'using' would have solved it.

                      --- In BCX@yahoogroups.com, "Joe" <yf777a@...> wrote:
                      >
                      >
                      > I tried it before, and every few seconds 2k more would
                      > be allocated to my app. I did not let it run long enough,
                      > but if I read this thread correctly, if the app ran for
                      > long enough, 2048*2048 would have eventually been allocated,
                      > before the circular queue started at the beginning. I don't
                      > remember the BCX string function, but when I saw the result
                      > I decided to use sprintf as I have in the past. Probably not
                      > enough from an efficency stand point.
                      >
                      > I'd be willing to help add an option at the end of such string
                      > functions, for a user supplied buffer... it would be less
                      > BASIC, but only an option. There definately would be an
                      > urgent warning in the help file regarding overflowing the
                      > user supplied buffer. As a sometimes 'c' programmer I never
                      > did such a thing ;-) ---- sure sure.
                      >
                      > I think the overall efficency it some instances would be
                      > worth using such an option. Maybe the effort and overhead
                      > is not worth it. I once thought of maintaining my own BCX,
                      > with things such as this, but it would be difficult to merge
                      > and maintain with the main BCX; and doubt I would have the
                      > time. But since I started dabbling in BCX 5 years ago, BCX
                      > makes it easy to drop down to c. Overall, BCX makes coding
                      > much easier than c. From what I have read you have had a
                      > few to several programmers make a great set of tools.
                      >
                      > -Joe
                      >
                      > --- In BCX@yahoogroups.com, "Kevin Diggins" <ktdiggins@> wrote:
                      > >
                      > > --- In BCX@yahoogroups.com, "Joe" <yf777a@> wrote:
                      > > >
                      > > > So, it would be a bad idea to repeated call certain
                      > > > BCX string functions in say handling WM_TIMER?
                      > >
                      > > Not necessarily, although if you are thinking of doing so,
                      > > some spot checking of the results would be prudent.
                      > >
                      >
                    • Ljubisa Knezevic
                      ... OK, I was wrong. For some reason I thought that each call of calloc/malloc must be followed by free before exiting program. Sorry for raising this
                      Message 10 of 10 , Aug 4, 2008
                      View Source
                      • 0 Attachment
                        --- In BCX@yahoogroups.com, "Kevin Diggins" <ktdiggins@...> wrote:
                        >
                        > --- In BCX@yahoogroups.com, Doyle Whisenant <mekanixx@> wrote:
                        > >
                        > > It's been my understanding that when *any* program exits, all of the
                        > > memory was released back to the system. No matter how the memory was
                        > > allocated. Of course, it wouldn't be the first time I was wrong. ;-)
                        > >
                        > > Doyle
                        >
                        > If you are wrong, you have lots of company.
                        >
                        > It is my understanding that memory leaks occur within a "running"
                        > program and, if left unattended, the leak will eventually crash the
                        > "running" program and sometimes even crash the operating system.
                        >
                        > Once the operating system is signaled that a program has terminated,
                        > the resources that the operating system allocated to the program at
                        > startup are recovered for re-use by the operating system.
                        >

                        OK, I was wrong. For some reason I thought that each call of
                        calloc/malloc must be followed by "free" before exiting program.

                        Sorry for raising this question, I should have look at some tutorial
                        about dynamic allocation before asking this.

                        Ljubisa
                      Your message has been successfully submitted and would be delivered to recipients shortly.