我一直收到检测到Heap Corruption的错误.我在这里已经阅读了几个问题,但我无法在我的代码中找到导致这种情况的原因.我正在尝试创建一个2d数组,它将保存从文本文件中读取的矩阵.
// Create a 2d matrix to hold the matrix (i = rows, j = columns)
matrix = new int*[cols];
for(int i = 0; i <= cols; i++) {
matrix[i] = new int[rows];
}
// Populate the matrix from the text file
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
inputFile >> matrix[i][j];
}
}
Run Code Online (Sandbox Code Playgroud)
我的析构函数是:
for(int i = 0; i <= cols; i++) {
delete[] matrix[i]; …Run Code Online (Sandbox Code Playgroud) 该类旨在确定文本的语言; 用户必须输入英语,丹麦语,意大利语和拉丁语的4个文本,然后输入他想要确定其语言的文本.控制台说
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at Riconoscimento2.creaTabellaTotale(Riconoscimento2.java:365)
at Riconoscimento2.main(Riconoscimento2.java:25)
Run Code Online (Sandbox Code Playgroud)
我在运行配置中使用eclipse - 我写的参数-Xms2g-Xmx3g.我不明白问题出在哪里.
代码是
import java.io.*;
import java.util.*;
import prog.io.*;
public class Riconoscimento2 {
public static void main(String[] args) {
char[] array = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ' '};
System.out.println("Immetti l'intero n per il calcolo degli n-grammi "); // questa istruzione richiede di immettere …Run Code Online (Sandbox Code Playgroud) void fun()
{
A *a = new A; //Here A is a class
} //a should be deleted in fun()'s scope
int main()
{
fun();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
创建的对象存在于免费存储中,main()函数无法使用.为什么要在免费商店上创建对象.是的,我们可以将对象引用传递给main函数,但我们甚至可以传递对象的副本(即使不使用new运算符创建).那么new和delete运算符的确切用法是什么?
我为一个简单的测试编写了一个简单的代码.
#include <stdio.h>
typedef struct
{
void* Data;
}List;
void x()
{
getchar();
int i;
List* myList[100000];
for(i = 0; i < 100000; i++)
{
myList[i] = (List*)malloc(sizeof(List)*1024*1024);
}
getchar();
for(i = 0; i < 100000; i++)
{
free(myList[i]);
}
}
int main()
{
x();
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我看过"taskmgr"中的程序,我看过: - 540K - 4.500K - 544K(什么是4K差异?)
我是一名新的C开发人员.我已经用Java编程了3年了.我注意到我必须用C做手动内存分配.
但是,当涉及到指针和内存分配时,我仍然不明确.我会说出我理解的内容,如果有人对我要说的话有任何评论,请指正.
所以我要说:
int *a;
Run Code Online (Sandbox Code Playgroud)
所以这样做会创建一个名为a的指针,指向一个整数值.
int *a = address;
Run Code Online (Sandbox Code Playgroud)
如果我打印地址,我会得到地址.
假设我想要价值,我做我们所谓的解除引用和
int *a = *value;
Run Code Online (Sandbox Code Playgroud)
如果我在这种情况下打印值,我会得到存储在内存中的实际数字.
我注意到在我使用的电子书中,有时候,我们在堆中分配内存.总是这样吗?每次我需要使用一个字符串的指针,例如使用char*,我必须使用alloc()和sizeof()分别根据预期类型的大小分配内存?
大多数人似乎建议通过编辑/usr/share/tomcat6/bin/catalina.sh文件为Tomcat6设置Java/Tomcat堆内存大小,并添加如下内容:
# Set specific memory requirements for Tomcat6 (for server with ~512MB RAM).
CATALINA_OPTS="$CATALINA_OPTS -server -Xms128m -Xmx256m"
Run Code Online (Sandbox Code Playgroud)
我正在尝试构建一个Ansible playbook来在Ubuntu上配置基于Tomcat的服务器,而且我似乎不喜欢整个自定义catalina.sh文件是理想的 - 是否有一些其他配置文件或本地设置文件/ Tomcat和/或Java用来获取Xms和Xmx值的系统?
或者......大多数人都使用自定义的catalina.sh文件,而我只是在一个小山丘上建造一座山?
请查看以下代码
public void createHash() throws IOException
{
System.out.println("Hash Creation Started");
StringBuffer hashIndex = new StringBuffer("");
AmazonS3 s3 = new AmazonS3Client(new ClasspathPropertiesFileCredentialsProvider());
Region usWest2 = Region.getRegion(Regions.US_EAST_1);
s3.setRegion(usWest2);
strBuffer = new StringBuffer("");
try
{
//List all the Buckets
List<Bucket>buckets = s3.listBuckets();
for(int i=0;i<buckets.size();i++)
{
System.out.println("- "+(buckets.get(i)).getName());
}
//Downloading the Object
System.out.println("Downloading Object");
S3Object s3Object = s3.getObject(new GetObjectRequest("JsonBucket", "Articles_4.json"));
System.out.println("Content-Type: " + s3Object.getObjectMetadata().getContentType());
//Read the JSON File
BufferedReader reader = new BufferedReader(new InputStreamReader(s3Object.getObjectContent()));
while (true) {
String line = reader.readLine();
if (line == …Run Code Online (Sandbox Code Playgroud) 是否更快使用++(a = b);而不是a = b + 1;?
据我了解,第一种方法包括以下操作:
b来aa内存增量而第二种方法是:
b和1到堆栈a它实际上需要更少的周期吗?或者编译器(例如gcc)是否进行了优化,因此它没有什么区别?
我正在尝试使用Java中的此数组创建和排序堆.我在maxHeap函数中不断获得数组索引超出范围的异常.代码似乎对我有意义,所以我不确定错误来自哪里.
谁知道我做错了什么?
public static void main(String[] args) {
int[] array = { 5, 16, 10, 7, 43, 12, 75, 33, 47, 3, 2489, 591, 6639, 557, 84, 9054, 17, 8841, 99, 701, 21, 78, 9, 36, 839};
heapSort(array3);
System.out.println("Heap Sort:");
printArray(array3);
}
public static void createHeap(int []A){
int n = A.length-1;
for(int i=n/2;i>=0;i--){
maxheap(A,i);
}
}
public static void maxheap(int[] A, int i){
int n = A.length;
int largest;
int left=2*i;
int right=2*i+1;
if(left <= n && A[left] > A[i]){ …Run Code Online (Sandbox Code Playgroud) 我一直在努力实现堆算法的递归版本.以下是伪代码的链接:http://en.wikipedia.org/wiki/Heap%27s_algorithm
在我到达递归部分之前,一切都很顺利.我知道我还没有交换元素,但我没有那么远.在我使用gcc调试器告知我存在分段错误之前,运行失败而没有显示错误.这是我的代码:
#include <string>
#include <iostream>
using namespace std;
string* permute(int n, string array[2]){
if (n==1){
return array;
}
else{
for(int c=1; c<=n;c++){
permute(n--,array);
}
}
}
int main() {
string array[2]={"a","b"};
permute(2,array);
return 0;
}
Run Code Online (Sandbox Code Playgroud) heap ×10
c++ ×4
java ×4
c ×2
memory ×2
algorithm ×1
allocation ×1
amazon-ec2 ×1
compilation ×1
constructor ×1
exception ×1
heapsort ×1
linux ×1
memory-leaks ×1
new-operator ×1
performance ×1
permutation ×1
recursion ×1
sorting ×1
tomcat ×1