Waitrud Weber’s blog

things and reminders for memories

windows-make: c++: about new array.

new itself is recognised on windows OS in mingw compilation.

> mingw32-c++.exe main.cpp

> .\a.exe
main starts.
main ends.

main.cpp  Sat Apr 17 13:04:15 2021
  1 :#include 
  2 :
  3 :char* m_data = NULL;
  4 :int m_bufferSize = 0;
  5 :int main() {
  6 :	printf ("main starts.\r\n");
  7 :
  8 :	int dataLength = 255;
  9 :
 10 :	// Allocate the array
 11 :	m_data = new char[m_bufferSize = dataLength];
 12 :
 13 :	printf ("main ends.\r\n");
 14 :	return 0;
 15 :}
 16 :
 17 :

---

(20210417: winmain_001.cpp cmpilation, it doesn't start well std allocation error)

WM_MESSG 004: 131 *(p_evt->uMsg):131 uMsg:131 p_evt->uMsg: 2685016 &uMsg: 2685016
SoundEffect::SoundEffect() starts.
SoundEffect::SoundEffect() ends.
WM_MESSG 000: hWnd 721770: uMsg 1: wParam 0: lParam 2685424: canvas 4354452: btc 4354464: *(p_evt->uMsg) 1:
SoundEffect::SoundEffect(const int noteInfo, const int arraySize) starts.
Allocation of m_data starts.
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

---

(20210417: it process well on the part of code of sounds-011 as same as avbove.)

> .\winmain_011.exe
main starts.
allocaton well:
SoundEffect::SoundEffect(const int noteInfo, const int arraySize) starts.
Allocation of m_data starts.
Allocation of m_data ends.
SoundEffect::SoundEffect(const int noteInfo[], const int arraySize) ends.
main ends.

 

.\main.cpp  Sat Apr 17 17:30:09 2021
  1 :#include 
  2 :
  3 :#include "sounds-011.h"
  4 :
  5 :char* m_data = NULL;
  6 :int m_bufferSize = 0;
  7 :
  8 :int b_data[255];
  9 :
 10 :int main() {
 11 :	printf ("main starts.\r\n");
 12 :
 13 :	int dataLength = 255;
 14 :
 15 :	// Allocate the array
 16 :	m_data = new char[m_bufferSize = dataLength];
 17 :
 18 :	printf("allocaton well: \r\n");
 19 :
 20 :	SoundEffect* as = (SoundEffect*) new SoundEffect( (int*) b_data, 255);
 21 :
 22 :	printf ("main ends.\r\n");
 23 :	return 0;
 24 :}
 25 :
 26 :