• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <iostream>
17 #include <cstdlib>
18 #include <cstring>
19 #include <vector>
20 
21 #include "logging.h"
22 
23 #pragma clang optimize off
24 
25 namespace {
26 const size_t MB_PER_BYTE = 0x100000;
27 }
28 
main(int agrc,char * agrv[])29 int main(int agrc, char* agrv[])
30 {
31     std::vector<char*> cache;
32     size_t size = 0;
33     char *buf = nullptr;
34 
35     for (int i = 1; i < agrc; i++) {
36         size = atoi(agrv[i]);
37         if (size <= 0) {
38             HILOG_INFO(LOG_CORE, "ready malloc size(%zu)Mb invalid", size);
39             continue;
40         }
41         buf = (char *)malloc(size * MB_PER_BYTE);
42         if (buf == nullptr) {
43             const int bufferSize = 1024;
44             char buffer[bufferSize] = { 0 };
45             strerror_r(errno, buffer, bufferSize);
46             HILOG_ERROR(LOG_CORE, "malloc %zu fail, err(%s:%d)", size, buffer, errno);
47             continue;
48         }
49         cache.emplace(cache.begin() + i - 1, buf);
50     }
51     while (true) {};
52     return 0;
53 }
54 
55 #pragma clang optimize on
56