首页 \ 问答 \ 删除pthread_t *(deleting pthread_t*)

删除pthread_t *(deleting pthread_t*)

我写了一个小的pthread多线程编程,我想清理我创建的pthred_t数组。 但是当我这样做时,我得到一个错误,即检测到了一个滑动条。 如何删除阵列,或者我根本不需要。 代码运行良好,没有释放内存,但在我看来,下面的代码导致(小)内存韭菜。 谢谢

pthread_t* threadNumber = new pthread_t (4);
args var;
var.matrixA=matrixA;
var.matrixB=matrixB;
var.matrixC=matrixC;
var.alpha=alpha;
var.beta=beta;
var.cellCount=0;
var.maxCells=cColumns*cRows;

for (int i =0 ;i<4;++i)
  pthread_create(&threadNumber[i],&attr,matrixMultiply,(void *) (&var));

for(int i=0;i<4;++i)
  pthread_join(threadNumber[i],NULL);

printMatrix(matrixA,aRows,aColumns);
printMatrix(matrixB,bRows,bColumns);
printMatrix(matrixC,cRows,cColumns);

//delete threadNumber;
//this caused a memory trash

I wrote a small pthread multithreadding programming and i wanted to clean up the pthred_t array which i created. But when I do it I get the error that a glib has been detected. How can I delete the array, or do I simply not need to. The code runs fine without the freeing of the memory but in my opinion the code below causes a (small) memory leek. Thanks

pthread_t* threadNumber = new pthread_t (4);
args var;
var.matrixA=matrixA;
var.matrixB=matrixB;
var.matrixC=matrixC;
var.alpha=alpha;
var.beta=beta;
var.cellCount=0;
var.maxCells=cColumns*cRows;

for (int i =0 ;i<4;++i)
  pthread_create(&threadNumber[i],&attr,matrixMultiply,(void *) (&var));

for(int i=0;i<4;++i)
  pthread_join(threadNumber[i],NULL);

printMatrix(matrixA,aRows,aColumns);
printMatrix(matrixB,bRows,bColumns);
printMatrix(matrixC,cRows,cColumns);

//delete threadNumber;
//this caused a memory trash

原文:https://stackoverflow.com/questions/13108886
更新时间:2022-06-18 17:06

最满意答案

我相信他说他想从他的代码中删除内联注释。

最快的方法是在文件中为UPGRADE_WARNING执行查找:并手动删除它们。

要么,

您可以创建一个新的.Net程序来遍历源目录中的每个.vb文件,并使用StreamReader读取它们,然后一次将它们写出一行到同一个文件中,然后省略包含UPGRADE_WARNING的任何行: 。

如果你采取第二种方式,那么你可以更好地完成更多的vb.net编码。


   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim FileName As String = "c:\form1.vb"
        Dim SourceFile As System.IO.FileInfo = New FileInfo(FileName)
        Dim SourceTextStream As System.IO.TextReader = SourceFile.OpenText()

        Dim SourceFileContent() As String = Split(SourceTextStream.ReadToEnd(), vbCrLf)
        SourceTextStream.Close()

        Dim CurrentSourceLine As String
        Dim CurrentSourceLineNumber As Long

        Dim DestStream As StreamWriter = New StreamWriter(FileName)
        Dim LogStream As StreamWriter = New StreamWriter(FileName + ".log")

        For Each CurrentSourceLine In SourceFileContent
            CurrentSourceLineNumber += 1
            If InStr(CurrentSourceLine, "UPGRADE_WARNING") = 0 Then
                DestStream.WriteLine(CurrentSourceLine)
            Else
                ' Write to Log File
                LogStream.WriteLine("Line Skipped at number: " + CurrentSourceLineNumber.ToString())
            End If
        Next

        DestStream.Close()
        LogStream.Close()




    End Sub

I believe he is saying that he wants to remove the inline comments from his code.

Fastest way is to perform a find in files for UPGRADE_WARNING: and remove them by hand.

Or,

You could create a new .Net program to iterate through each .vb file in your source directory and read them in using a StreamReader and then write them out 1 line at a time to the same file and as you go omit any lines containing UPGRADE_WARNING:.

If you do the second way you will be that much better for having done some more vb.net coding.


   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim FileName As String = "c:\form1.vb"
        Dim SourceFile As System.IO.FileInfo = New FileInfo(FileName)
        Dim SourceTextStream As System.IO.TextReader = SourceFile.OpenText()

        Dim SourceFileContent() As String = Split(SourceTextStream.ReadToEnd(), vbCrLf)
        SourceTextStream.Close()

        Dim CurrentSourceLine As String
        Dim CurrentSourceLineNumber As Long

        Dim DestStream As StreamWriter = New StreamWriter(FileName)
        Dim LogStream As StreamWriter = New StreamWriter(FileName + ".log")

        For Each CurrentSourceLine In SourceFileContent
            CurrentSourceLineNumber += 1
            If InStr(CurrentSourceLine, "UPGRADE_WARNING") = 0 Then
                DestStream.WriteLine(CurrentSourceLine)
            Else
                ' Write to Log File
                LogStream.WriteLine("Line Skipped at number: " + CurrentSourceLineNumber.ToString())
            End If
        Next

        DestStream.Close()
        LogStream.Close()




    End Sub

相关问答

更多
  • .Net平台引入了很多先进的技术,导致了VB6和VB.Net之间产生了一个巨大的鸿沟 就语言功能上来讲,VB.net完全是为了.Net技术而生,具有更好的运行效率和更加强大的功能(某些方面甚至超过了C#) 从语法角度上来讲,VB.net成为了真正的OOP(面向对象语言),不但支持类的继承、派生,还支持委托、泛型等等更加高级的编程技术 如果你是从VB6升级到.net的话,建议要将VB.net当作一门新的语言来学。以VB6的经验来应用到VB.net上是会犯很多错误的 关于从VB6升级到VB.net的代 ...
  • .Net平台引入了很多先进的技术,导致了VB6和VB.Net之间产生了一个巨大的鸿沟 就语言功能上来讲,VB.net完全是为了.Net技术而生,具有更好的运行效率和更加强大的功能(某些方面甚至超过了C#) 从语法角度上来讲,VB.net成为了真正的OOP(面向对象语言),不但支持类的继承、派生,还支持委托、泛型等等更加高级的编程技术 如果你是从VB6升级到.net的话,建议要将VB.net当作一门新的语言来学。以VB6的经验来应用到VB.net上是会犯很多错误的 关于从VB6升级到VB.net的代码变换问题 ...
  • PixelsToTwips仅在32位项目中受支持。 请尝试以下操作,或使用Imports Microsoft.VisualBasic.Compatibility 。 请务必将Microsoft.VisualBasic.Compatibility作为参考。 Dim X As Single = Microsoft.VisualBasic.Compatibility.VB6.PixelsToTwipsX(eventArgs.X) Dim Y As Single = Microsoft.VisualBasic.Co ...
  • 有一个来自vb.net。 当您打开.vbp vb6项目时,它会询问您是否想自动将其转换为vb.net。 它做得不错,不包括第三方附加组件。 There is one that comes with vb.net. When you open a .vbp vb6 project, it asks if you would like to automatically convert it to vb.net. It does a pretty good job, exclusive of third part ...
  • 在VB6中,颜色表示为Longs,而在VB.NET中,颜色表示为Structures。 资源 在Visual Basic 6.0中,颜色由Long类型的值表示; 在Visual Basic 2008中,颜色是Color类型。 在Visual Basic 6.0中,提供了八种标准颜色的常量; 在Visual Basic 2008中,有超过100种命名颜色。 小费 若要查找不是标准颜色的Visual Basic 6.0颜色的等效值,可以使用ColorTranslator类并将其传递给Visual Basic 6 ...
  • 我相信他说他想从他的代码中删除内联注释。 最快的方法是在文件中为UPGRADE_WARNING执行查找:并手动删除它们。 要么, 您可以创建一个新的.Net程序来遍历源目录中的每个.vb文件,并使用StreamReader读取它们,然后一次将它们写出一行到同一个文件中,然后省略包含UPGRADE_WARNING的任何行: 。 如果你采取第二种方式,那么你可以更好地完成更多的vb.net编码。 Private Sub Button1_Click(ByVal sender As System.Objec ...
  • 我经常把人们推荐给http://vb.net-informations.com/crystal-report/vb.net_crystal_report_step_by_step.htm 基本上你需要添加Crystal引用(你需要安装Visual Studio运行时的Crystal报告),添加一个CrystalReportViewer然后使用一些代码: Imports CrystalDecisions.CrystalReports.Engine Public Class Form1 Private ...
  • 如果您将MZ工具包添加到您的VB6 IDE中,该工具包包含“关闭所有窗口”按钮(以及其他许多方便的功能)。 If you add the MZ Toolkit to your VB6 IDE, that includes a "close all windows" button (along with numerous other handy things).
  • 您需要声明一个委托,如下所示: Delegate Sub DeviceStateChangedDelegate(ByVal param As Integer) 然后在SetupCallBacks方法内部,您需要创建和调用您的委托,如下所示: Public Sub SetupCallBacks() ' Declare and instantiate the delegate Dim MTUSCRADeviceStateChangedNotify As DeviceStateChangedDe ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。