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 #include "logging.h"
21
22 #pragma clang optimize off
23
24 namespace {
25 const size_t MB_PER_BYTE = 0x100000;
26 }
27
main(int agrc,char * agrv[])28 int main(int agrc, char* agrv[])
29 {
30 std::vector<char*> cache;
31 size_t size = 0;
32 char *buf = nullptr;
33
34 for (int i = 1; i < agrc; i++) {
35 size = atoi(agrv[i]);
36 if (size <= 0) {
37 HILOG_INFO(LOG_CORE, "ready malloc size(%zu)Mb invalid", size);
38 continue;
39 }
40 buf = (char *)malloc(size * MB_PER_BYTE);
41 if (buf == nullptr) {
42 const int bufferSize = 256;
43 char buffer[bufferSize] = { 0 };
44 strerror_r(errno, buffer, bufferSize);
45 HILOG_ERROR(LOG_CORE, "malloc %zu fail, err(%s:%d)", size, buffer, errno);
46 continue;
47 }
48 cache.emplace(cache.begin() + i - 1, buf);
49 }
50 while (true) {};
51 return 0;
52 }
53
54 #pragma clang optimize on
55