Send MinGW-Notify mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.osdn.me/mailman/listinfo/mingw-notify
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of MinGW-Notify digest..."


Please do not reply to this notification; the sender address is unable to 
accept incoming e-mail.  If you wish to unsubscribe you can do so at 
https://lists.osdn.me/mailman/listinfo/mingw-notify.



Today's Topics:

   1. [mingw] #40686: std::string custom operator new/delete
      function (MinGW Notification List)
   2. [mingw] #40686: std::string custom operator new/delete
      function (MinGW Notification List)
   3. [SCM] mingw-dist (mingw) branch, master, updated.
      76ba19764ba1382040dfd630b433581f489c8a04 (MinGW Notification List)


----------------------------------------------------------------------

Message: 1
Date: Fri, 04 Sep 2020 16:45:07 +0900
From: MinGW Notification List <[email protected]>
To: OSDN Ticket System <[email protected]>
Subject: [MinGW-Notify] [mingw] #40686: std::string custom operator
        new/delete function
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

#40686: std::string custom operator new/delete function

  Open Date: 2020-08-30 18:32
Last Update: 2020-09-04 16:45

URL for this Ticket:
    https://osdn.net//projects/mingw/ticket/40686
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=40686

---------------------------------------------------------------------

Last Changes/Comment on this Ticket:
2020-09-04 16:45 Updated by: marvol

Comment:

So, you think it is because the implementation of the std::string is in an
external dll? It may explain that my operator new was not called.

Indeed, If I compile it with the "-static" linker option my operator new/delete
is called. But why was my operator delete called? Is it because the compiler
optimized the std::string destroy function to be inlined?

I am thinking about the experience that I had with std::vector - maybe it is
because the std::vector is a template that is compiled with the source.



---------------------------------------------------------------------
Ticket Status:

      Reporter: marvol
         Owner: (None)
          Type: Issues
        Status: Open
      Priority: 1 - Lowest
     MileStone: (None)
     Component: GCC
      Severity: 1 - Lowest
    Resolution: Works For Me
---------------------------------------------------------------------

Ticket details:

Hello,

I am writing a custom wrapper for new/delete allocations to get an aligned
memory. I noticed that if I use std::string, operator new/delete are not called
as it is in a linux version of g++ (operators new/delete are called). With the
default optimization level, operator new/delete is not called and with
optimization levels O1, O2, O3 only operator delete is called.

Source:

 1.  #include <string>
 2.  #include <cstdio>
 3.  #include <cstdlib>
 4.  
 5.  void* operator new(size_t size)
 6.  {
 7.          printf("Calling new: %zu", size);
 8.          void* address = malloc(size);
 9.  
10.          printf(" address: 0x%p\n", address);
11.          return address;
12.  }
13.  
14.  void* operator new[](size_t size)
15.  {
16.          printf("Calling new[]: %zu", size);
17.          void* address = malloc(size);
18.  
19.          printf(" address: 0x%p\n", address);
20.          return address;
21.  }
22.  
23.  void operator delete(void* address)
24.  {
25.          printf("Calling delete, address: 0x%p\n", address);
26.          free(address);
27.  }
28.  
29.  void operator delete[](void* address)
30.  {
31.          printf("Calling delete[], address: 0x%p\n", address);
32.          free(address);
33.  }
34.  
35.  struct Obj
36.  {
37.          std::string m_str;
38.  };
39.  
40.  void test()
41.  {
42.          Obj obj;
43.          obj.m_str = "long string ......................";
44.  }
45.  
46.  int main()
47.  {
48.          test();
49.  
50.          return 0;
51.  }

Compiling with the default optimization level:

  • g++ main.cpp -std=c++11 -o test.exe

Output:

  • NONE

Compiling with the O2 optimization level:

  • g++ main.cpp -std=c++11 -O2 -o test.exe

Output:

  • Calling delete, address: 0x00542098

I am using:

  • OS: Windows 7
  • Mingw: 5.4.1
  • Shell: cmd MINGW32_NT-6.1 MARTIN-LENOVO 1.0.18(0.48/3/2) 2012-11-21 22:34
    i686 Msys
  • Uname -a:
  • G++: g++ (MinGW.org GCC Build-2) 9.2.0
  • GCC: gcc (MinGW.org GCC Build-2) 9.2.0
  • ld: GNU ld (GNU Binutils) 2.32



-- 
Ticket information of MinGW - Minimalist GNU for Windows project
MinGW - Minimalist GNU for Windows Project is hosted on OSDN

Project URL: https://osdn.net/projects/mingw/
OSDN: https://osdn.net

URL for this Ticket:
    https://osdn.net/projects/mingw/ticket/40686
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=40686


------------------------------

Message: 2
Date: Fri, 04 Sep 2020 11:57:56 +0100
From: MinGW Notification List <[email protected]>
To: OSDN Ticket System <[email protected]>
Subject: [MinGW-Notify] [mingw] #40686: std::string custom operator
        new/delete function
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

#40686: std::string custom operator new/delete function

  Open Date: 2020-08-30 10:32
Last Update: 2020-09-04 11:57

URL for this Ticket:
    https://osdn.net//projects/mingw/ticket/40686
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=40686

---------------------------------------------------------------------

Last Changes/Comment on this Ticket:
2020-09-04 11:57 Updated by: keith

Comment:

Reply To marvol

    So, you think it is because the implementation of the std::string is in an
    external dll?

Yes ... in fact, I know it to be so.

    It may explain that my operator new was not called.

It does. There is a fundamental, and significant, difference between the
properties of ELF shared objects, as used on Linux, and the equivalent PE-coff
DLLs, as used on Windows. Do you know what it is?

    Indeed, If I compile it with the "-static" linker option my operator new/
    delete is called.

Actually, -static-libstdc++ is sufficient.

    But why was my operator delete called? Is it because the compiler optimized
    the std::string destroy function to be inlined?

Yes. You can study the effect of differing optimization levels, by compiling
with -S -o-, and examining the assembly output. At -O1 (and above), your Obj
class object is optimized away, and your test function includes exactly one
reference to a std::string method — likely a copy constructor — and then your
delete operator code is called; at -O2 (and -O3) even the delete call is
optimized away, and your code is in-lined. At no optimization level, is your
new operator ever called, but it is likely that whatever new operator
implementation std::string knows about is called, (by what I assume to be its
cryptically named copy constructor). That, in itself, is disturbing, because
you have a potentially incompatible new and delete pairing, at any optimization
level of -O1 or above.

    I am thinking about the experience that I had with std::vector - maybe it
    is because the std::vector is a template that is compiled with the source.

Maybe. You haven't shown me anything, which I might evaluate.



---------------------------------------------------------------------
Ticket Status:

      Reporter: marvol
         Owner: (None)
          Type: Issues
        Status: Open
      Priority: 1 - Lowest
     MileStone: (None)
     Component: GCC
      Severity: 1 - Lowest
    Resolution: Works For Me
---------------------------------------------------------------------

Ticket details:

Hello,

I am writing a custom wrapper for new/delete allocations to get an aligned
memory. I noticed that if I use std::string, operator new/delete are not called
as it is in a linux version of g++ (operators new/delete are called). With the
default optimization level, operator new/delete is not called and with
optimization levels O1, O2, O3 only operator delete is called.

Source:

 1.  #include <string>
 2.  #include <cstdio>
 3.  #include <cstdlib>
 4.  
 5.  void* operator new(size_t size)
 6.  {
 7.          printf("Calling new: %zu", size);
 8.          void* address = malloc(size);
 9.  
10.          printf(" address: 0x%p\n", address);
11.          return address;
12.  }
13.  
14.  void* operator new[](size_t size)
15.  {
16.          printf("Calling new[]: %zu", size);
17.          void* address = malloc(size);
18.  
19.          printf(" address: 0x%p\n", address);
20.          return address;
21.  }
22.  
23.  void operator delete(void* address)
24.  {
25.          printf("Calling delete, address: 0x%p\n", address);
26.          free(address);
27.  }
28.  
29.  void operator delete[](void* address)
30.  {
31.          printf("Calling delete[], address: 0x%p\n", address);
32.          free(address);
33.  }
34.  
35.  struct Obj
36.  {
37.          std::string m_str;
38.  };
39.  
40.  void test()
41.  {
42.          Obj obj;
43.          obj.m_str = "long string ......................";
44.  }
45.  
46.  int main()
47.  {
48.          test();
49.  
50.          return 0;
51.  }

Compiling with the default optimization level:

  • g++ main.cpp -std=c++11 -o test.exe

Output:

  • NONE

Compiling with the O2 optimization level:

  • g++ main.cpp -std=c++11 -O2 -o test.exe

Output:

  • Calling delete, address: 0x00542098

I am using:

  • OS: Windows 7
  • Mingw: 5.4.1
  • Shell: cmd MINGW32_NT-6.1 MARTIN-LENOVO 1.0.18(0.48/3/2) 2012-11-21 22:34
    i686 Msys
  • Uname -a:
  • G++: g++ (MinGW.org GCC Build-2) 9.2.0
  • GCC: gcc (MinGW.org GCC Build-2) 9.2.0
  • ld: GNU ld (GNU Binutils) 2.32



-- 
Ticket information of MinGW - Minimalist GNU for Windows project
MinGW - Minimalist GNU for Windows Project is hosted on OSDN

Project URL: https://osdn.net/projects/mingw/
OSDN: https://osdn.net

URL for this Ticket:
    https://osdn.net/projects/mingw/ticket/40686
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=40686


------------------------------

Message: 3
Date: Sat, 05 Sep 2020 00:46:58 +0900
From: MinGW Notification List <[email protected]>
To: [email protected]
Subject: [MinGW-Notify] [SCM] mingw-dist (mingw) branch, master,
        updated. 76ba19764ba1382040dfd630b433581f489c8a04
Message-ID: <[email protected]>

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to "mingw-dist" repository
containing the "mingw" project.

The branch, master has been updated
       via  76ba19764ba1382040dfd630b433581f489c8a04 (commit)
      from  90514f97f70ae8748bc0db7277eb620c10ad8eb0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 76ba19764ba1382040dfd630b433581f489c8a04
Author: Keith Marshall <[email protected]>
Date:   Fri Sep 4 16:44:21 2020 +0100

    Publish expat-2.2.9 package set.

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                 | 10 ++++++
 common/issue.log          |  2 +-
 mingw32/issue.log         |  4 +--
 mingw32/mingw32-expat.xml | 86 ++++++++++++++++++++++++++++++++---------------
 4 files changed, 72 insertions(+), 30 deletions(-)


hooks/post-receive
-- 
mingw-dist (mingw)



------------------------------

Subject: Digest Footer

_______________________________________________
MinGW-Notify mailing list
[email protected]
https://lists.osdn.me/mailman/listinfo/mingw-notify


------------------------------

End of MinGW-Notify Digest, Vol 36, Issue 5
*******************************************

Reply via email to