WeixiangYan/CodeTransOcean huggingface dataset:
Task: Memory allocation



C#: using System;
using System.Runtime.InteropServices;

public unsafe class Program
{
    public static unsafe void HeapMemory()
    {
        const int HEAP_ZERO_MEMORY = 0x00000008;
        const int size = 1000;
        int ph = GetProcessHeap();
        void* pointer = HeapAlloc(ph, HEAP_ZERO_MEMORY, size);
        if (pointer == null)
            throw new OutOfMemoryException();
        Console.WriteLine(HeapSize(ph, 0, pointer));
        HeapFree(ph, 0, pointer);
    }

    public static unsafe void StackMemory()
    {
        byte* buffer = stackalloc byte[1000];
        
    }
    public static void Main(string[] args)
    {
        HeapMemory();
        StackMemory();
    }
    [DllImport("kernel32")]
    static extern void* HeapAlloc(int hHeap, int flags, int size);
    [DllImport("kernel32")]
    static extern bool HeapFree(int hHeap, int flags, void* block);
    [DllImport("kernel32")]
    static extern int GetProcessHeap();
    [DllImport("kernel32")]
    static extern int HeapSize(int hHeap, int flags, void* block);

}








Fortran: program allocation_test
    implicit none
    real, dimension(:), allocatable :: vector
    real, dimension(:, :), allocatable :: matrix
    real, pointer :: ptr
    integer, parameter :: n = 100 

    allocate(vector(n))      
    allocate(matrix(n, n))   
    allocate(ptr)            

    deallocate(vector)       
    deallocate(matrix)       
    deallocate(ptr)          
end program allocation_test
Task: Memory allocation


C++: #include <string>

int main()
{
  int* p;

  p = new int;    
  delete p;       

  p = new int(2); 
  delete p;       

  std::string* p2;

  p2 = new std::string; 
  delete p2;            

  p = new int[10]; 
  delete[] p;      

  p2 = new std::string[10]; 
  delete[] p2;              
}









Fortran: program allocation_test
    implicit none
    real, dimension(:), allocatable :: vector
    real, dimension(:, :), allocatable :: matrix
    real, pointer :: ptr
    integer, parameter :: n = 100 

    allocate(vector(n))      
    allocate(matrix(n, n))   
    allocate(ptr)            

    deallocate(vector)       
    deallocate(matrix)       
    deallocate(ptr)          
end program allocation_test
Task: Memory allocation

C: #include <stdlib.h>


#define SIZEOF_MEMB (sizeof(int))
#define NMEMB 100

int main()
{
  int *ints = malloc(SIZEOF_MEMB*NMEMB);
  
  ints = realloc(ints, sizeof(int)*(NMEMB+1));
  
  int *int2 = calloc(NMEMB, SIZEOF_MEMB);
  
  free(ints); free(int2);
  return 0;
}










Fortran: program allocation_test
    implicit none
    real, dimension(:), allocatable :: vector
    real, dimension(:, :), allocatable :: matrix
    real, pointer :: ptr
    integer, parameter :: n = 100 

    allocate(vector(n))      
    allocate(matrix(n, n))   
    allocate(ptr)            

    deallocate(vector)       
    deallocate(matrix)       
    deallocate(ptr)          
end program allocation_test
Task: Memory allocation





Java: 

Object foo = new Object(); 
int[] fooArray = new int[size]; 
int x = 0; 






Fortran: program allocation_test
    implicit none
    real, dimension(:), allocatable :: vector
    real, dimension(:, :), allocatable :: matrix
    real, pointer :: ptr
    integer, parameter :: n = 100 

    allocate(vector(n))      
    allocate(matrix(n, n))   
    allocate(ptr)            

    deallocate(vector)       
    deallocate(matrix)       
    deallocate(ptr)          
end program allocation_test
Task: Memory allocation







Python: >>> from array import array
>>> argslist = [('l', []), ('c', 'hello world'), ('u', u'hello \u2641'),
	('l', [1, 2, 3, 4, 5]), ('d', [1.0, 2.0, 3.14])]
>>> for typecode, initializer in argslist:
	a = array(typecode, initializer)
	print a
	del a

	
array('l')
array('c', 'hello world')
array('u', u'hello \u2641')
array('l', [1, 2, 3, 4, 5])
array('d', [1.0, 2.0, 3.1400000000000001])
>>>




Fortran: program allocation_test
    implicit none
    real, dimension(:), allocatable :: vector
    real, dimension(:, :), allocatable :: matrix
    real, pointer :: ptr
    integer, parameter :: n = 100 

    allocate(vector(n))      
    allocate(matrix(n, n))   
    allocate(ptr)            

    deallocate(vector)       
    deallocate(matrix)       
    deallocate(ptr)          
end program allocation_test
Task: Memory allocation

C: #include <stdlib.h>


#define SIZEOF_MEMB (sizeof(int))
#define NMEMB 100

int main()
{
  int *ints = malloc(SIZEOF_MEMB*NMEMB);
  
  ints = realloc(ints, sizeof(int)*(NMEMB+1));
  
  int *int2 = calloc(NMEMB, SIZEOF_MEMB);
  
  free(ints); free(int2);
  return 0;
}









COBOL:        PROGRAM-ID. memory-allocation.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  based-data              PIC X(20) VALUE "Hello, World!"
                                   BASED.

       PROCEDURE DIVISION.
           
           ALLOCATE based-data INITIALIZED
           DISPLAY based-data
           FREE based-data

           GOBACK
           .
Task: Memory allocation



C#: using System;
using System.Runtime.InteropServices;

public unsafe class Program
{
    public static unsafe void HeapMemory()
    {
        const int HEAP_ZERO_MEMORY = 0x00000008;
        const int size = 1000;
        int ph = GetProcessHeap();
        void* pointer = HeapAlloc(ph, HEAP_ZERO_MEMORY, size);
        if (pointer == null)
            throw new OutOfMemoryException();
        Console.WriteLine(HeapSize(ph, 0, pointer));
        HeapFree(ph, 0, pointer);
    }

    public static unsafe void StackMemory()
    {
        byte* buffer = stackalloc byte[1000];
        
    }
    public static void Main(string[] args)
    {
        HeapMemory();
        StackMemory();
    }
    [DllImport("kernel32")]
    static extern void* HeapAlloc(int hHeap, int flags, int size);
    [DllImport("kernel32")]
    static extern bool HeapFree(int hHeap, int flags, void* block);
    [DllImport("kernel32")]
    static extern int GetProcessHeap();
    [DllImport("kernel32")]
    static extern int HeapSize(int hHeap, int flags, void* block);

}







COBOL:        PROGRAM-ID. memory-allocation.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  based-data              PIC X(20) VALUE "Hello, World!"
                                   BASED.

       PROCEDURE DIVISION.
           
           ALLOCATE based-data INITIALIZED
           DISPLAY based-data
           FREE based-data

           GOBACK
           .
Task: Memory allocation


C++: #include <string>

int main()
{
  int* p;

  p = new int;    
  delete p;       

  p = new int(2); 
  delete p;       

  std::string* p2;

  p2 = new std::string; 
  delete p2;            

  p = new int[10]; 
  delete[] p;      

  p2 = new std::string[10]; 
  delete[] p2;              
}








COBOL:        PROGRAM-ID. memory-allocation.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  based-data              PIC X(20) VALUE "Hello, World!"
                                   BASED.

       PROCEDURE DIVISION.
           
           ALLOCATE based-data INITIALIZED
           DISPLAY based-data
           FREE based-data

           GOBACK
           .
Task: Memory allocation





Java: 

Object foo = new Object(); 
int[] fooArray = new int[size]; 
int x = 0; 





COBOL:        PROGRAM-ID. memory-allocation.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  based-data              PIC X(20) VALUE "Hello, World!"
                                   BASED.

       PROCEDURE DIVISION.
           
           ALLOCATE based-data INITIALIZED
           DISPLAY based-data
           FREE based-data

           GOBACK
           .
Task: Memory allocation







Python: >>> from array import array
>>> argslist = [('l', []), ('c', 'hello world'), ('u', u'hello \u2641'),
	('l', [1, 2, 3, 4, 5]), ('d', [1.0, 2.0, 3.14])]
>>> for typecode, initializer in argslist:
	a = array(typecode, initializer)
	print a
	del a

	
array('l')
array('c', 'hello world')
array('u', u'hello \u2641')
array('l', [1, 2, 3, 4, 5])
array('d', [1.0, 2.0, 3.1400000000000001])
>>>



COBOL:        PROGRAM-ID. memory-allocation.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  based-data              PIC X(20) VALUE "Hello, World!"
                                   BASED.

       PROCEDURE DIVISION.
           
           ALLOCATE based-data INITIALIZED
           DISPLAY based-data
           FREE based-data

           GOBACK
           .
Task: Memory allocation




Go: func inc(n int) {
    x := n + 1
    println(x)
}






COBOL:        PROGRAM-ID. memory-allocation.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  based-data              PIC X(20) VALUE "Hello, World!"
                                   BASED.

       PROCEDURE DIVISION.
           
           ALLOCATE based-data INITIALIZED
           DISPLAY based-data
           FREE based-data

           GOBACK
           .
Task: Stair-climbing puzzle



C#: void step_up() {
    while (!step()) step_up();
}









Ada: procedure Step_Up is
begin
   while not Step loop
      Step_Up;
   end loop;
end Step_Up;
Task: Stair-climbing puzzle

C: void step_up(void)
{
    while (!step()) {
        step_up();
    }
}











Ada: procedure Step_Up is
begin
   while not Step loop
      Step_Up;
   end loop;
end Step_Up;
Task: Stair-climbing puzzle


C++: void step_up()
{
  while (!step()) step_up();
}










Ada: procedure Step_Up is
begin
   while not Step loop
      Step_Up;
   end loop;
end Step_Up;
Task: Stair-climbing puzzle




Go: func step_up(){for !step(){step_up()}}








Ada: procedure Step_Up is
begin
   while not Step loop
      Step_Up;
   end loop;
end Step_Up;
Task: Stair-climbing puzzle





Java: public void stepUp() {
  while (!step()) stepUp();
}







Ada: procedure Step_Up is
begin
   while not Step loop
      Step_Up;
   end loop;
end Step_Up;
Task: Stair-climbing puzzle







Python: def step_up1():
  
  deficit = 1
  while deficit > 0:
    if step():
      deficit -= 1
    else:
      deficit += 1





Ada: procedure Step_Up is
begin
   while not Step loop
      Step_Up;
   end loop;
end Step_Up;
Task: Stair-climbing puzzle

C: void step_up(void)
{
    while (!step()) {
        step_up();
    }
}
Task: Stair-climbing puzzle



C#: void step_up() {
    while (!step()) step_up();
}
Task: Stair-climbing puzzle


C++: void step_up()
{
  while (!step()) step_up();
}
Task: Stair-climbing puzzle





Java: public void stepUp() {
  while (!step()) stepUp();
}
Task: Stair-climbing puzzle







Python: def step_up1():
  
  deficit = 1
  while deficit > 0:
    if step():
      deficit -= 1
    else:
      deficit += 1
Task: Stair-climbing puzzle




Go: func step_up(){for !step(){step_up()}}
Task: Stair-climbing puzzle



C#: void step_up() {
    while (!step()) step_up();
}








Fortran: module StairRobot
  implicit none

contains

  logical function step()
    
    step = .true.     
  end function step

  recursive subroutine step_up_rec
    do while ( .not. step() )
       call step_up_rec
    end do
  end subroutine step_up_rec

  subroutine step_up_iter
    integer :: i = 0
    do while ( i < 1 )
       if ( step() ) then
          i = i + 1
       else
          i = i - 1
       end if
    end do
  end subroutine step_up_iter

end module StairRobot
Task: Stair-climbing puzzle


C++: void step_up()
{
  while (!step()) step_up();
}









Fortran: module StairRobot
  implicit none

contains

  logical function step()
    
    step = .true.     
  end function step

  recursive subroutine step_up_rec
    do while ( .not. step() )
       call step_up_rec
    end do
  end subroutine step_up_rec

  subroutine step_up_iter
    integer :: i = 0
    do while ( i < 1 )
       if ( step() ) then
          i = i + 1
       else
          i = i - 1
       end if
    end do
  end subroutine step_up_iter

end module StairRobot
Task: Stair-climbing puzzle

C: void step_up(void)
{
    while (!step()) {
        step_up();
    }
}










Fortran: module StairRobot
  implicit none

contains

  logical function step()
    
    step = .true.     
  end function step

  recursive subroutine step_up_rec
    do while ( .not. step() )
       call step_up_rec
    end do
  end subroutine step_up_rec

  subroutine step_up_iter
    integer :: i = 0
    do while ( i < 1 )
       if ( step() ) then
          i = i + 1
       else
          i = i - 1
       end if
    end do
  end subroutine step_up_iter

end module StairRobot
Task: Stair-climbing puzzle




Go: func step_up(){for !step(){step_up()}}







Fortran: module StairRobot
  implicit none

contains

  logical function step()
    
    step = .true.     
  end function step

  recursive subroutine step_up_rec
    do while ( .not. step() )
       call step_up_rec
    end do
  end subroutine step_up_rec

  subroutine step_up_iter
    integer :: i = 0
    do while ( i < 1 )
       if ( step() ) then
          i = i + 1
       else
          i = i - 1
       end if
    end do
  end subroutine step_up_iter

end module StairRobot
Task: Stair-climbing puzzle





Java: public void stepUp() {
  while (!step()) stepUp();
}






Fortran: module StairRobot
  implicit none

contains

  logical function step()
    
    step = .true.     
  end function step

  recursive subroutine step_up_rec
    do while ( .not. step() )
       call step_up_rec
    end do
  end subroutine step_up_rec

  subroutine step_up_iter
    integer :: i = 0
    do while ( i < 1 )
       if ( step() ) then
          i = i + 1
       else
          i = i - 1
       end if
    end do
  end subroutine step_up_iter

end module StairRobot
Task: Stair-climbing puzzle







Python: def step_up1():
  
  deficit = 1
  while deficit > 0:
    if step():
      deficit -= 1
    else:
      deficit += 1




Fortran: module StairRobot
  implicit none

contains

  logical function step()
    
    step = .true.     
  end function step

  recursive subroutine step_up_rec
    do while ( .not. step() )
       call step_up_rec
    end do
  end subroutine step_up_rec

  subroutine step_up_iter
    integer :: i = 0
    do while ( i < 1 )
       if ( step() ) then
          i = i + 1
       else
          i = i - 1
       end if
    end do
  end subroutine step_up_iter

end module StairRobot
Task: Hostname



C#: System.Net.Dns.GetHostName();









Ada: with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Sockets;

procedure Demo is
begin
   Put_Line (GNAT.Sockets.Host_Name);
end Demo;
Task: Hostname

C: #include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <unistd.h>
 
int main(void)
{
 char name[_POSIX_HOST_NAME_MAX + 1];
 return gethostname(name, sizeof name) == -1 || printf("%s\n", name) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}











Ada: with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Sockets;

procedure Demo is
begin
   Put_Line (GNAT.Sockets.Host_Name);
end Demo;
Task: Hostname




Go: package main

import (
	"fmt"
	"os"
)

func main() {
	fmt.Println(os.Hostname())
}








Ada: with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Sockets;

procedure Demo is
begin
   Put_Line (GNAT.Sockets.Host_Name);
end Demo;
Task: Hostname





Java: import java.net.*;
class DiscoverHostName {
 public static void main(final String[] args) {
  try {
   System.out.println(InetAddress.getLocalHost().getHostName());
  } catch (UnknownHostException e) { 
  }
 }
}







Ada: with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Sockets;

procedure Demo is
begin
   Put_Line (GNAT.Sockets.Host_Name);
end Demo;
Task: Hostname







Python: import socket
host = socket.gethostname()





Ada: with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Sockets;

procedure Demo is
begin
   Put_Line (GNAT.Sockets.Host_Name);
end Demo;
Task: Hostname








VB: Set objNetwork = CreateObject("WScript.Network")
WScript.Echo objNetwork.ComputerName




Ada: with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Sockets;

procedure Demo is
begin
   Put_Line (GNAT.Sockets.Host_Name);
end Demo;
Task: Hostname

C: #include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <unistd.h>
 
int main(void)
{
 char name[_POSIX_HOST_NAME_MAX + 1];
 return gethostname(name, sizeof name) == -1 || printf("%s\n", name) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
Task: Hostname





Java: import java.net.*;
class DiscoverHostName {
 public static void main(final String[] args) {
  try {
   System.out.println(InetAddress.getLocalHost().getHostName());
  } catch (UnknownHostException e) { 
  }
 }
}
Task: Hostname




Go: package main

import (
	"fmt"
	"os"
)

func main() {
	fmt.Println(os.Hostname())
}
Task: Hostname








VB: Set objNetwork = CreateObject("WScript.Network")
WScript.Echo objNetwork.ComputerName
Task: Hostname



C#: System.Net.Dns.GetHostName();
Task: Hostname







Python: import socket
host = socket.gethostname()
Task: Hostname



C#: System.Net.Dns.GetHostName();








Fortran: program HostTest
  character(len=128) :: name 
  call hostnm(name)
  print *, name
end program HostTest
Task: Hostname

C: #include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <unistd.h>
 
int main(void)
{
 char name[_POSIX_HOST_NAME_MAX + 1];
 return gethostname(name, sizeof name) == -1 || printf("%s\n", name) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}










Fortran: program HostTest
  character(len=128) :: name 
  call hostnm(name)
  print *, name
end program HostTest
Task: Hostname





Java: import java.net.*;
class DiscoverHostName {
 public static void main(final String[] args) {
  try {
   System.out.println(InetAddress.getLocalHost().getHostName());
  } catch (UnknownHostException e) { 
  }
 }
}






Fortran: program HostTest
  character(len=128) :: name 
  call hostnm(name)
  print *, name
end program HostTest
Task: Hostname







Python: import socket
host = socket.gethostname()




Fortran: program HostTest
  character(len=128) :: name 
  call hostnm(name)
  print *, name
end program HostTest
Task: Hostname








VB: Set objNetwork = CreateObject("WScript.Network")
WScript.Echo objNetwork.ComputerName



Fortran: program HostTest
  character(len=128) :: name 
  call hostnm(name)
  print *, name
end program HostTest
Task: Hostname






PHP: echo $_SERVER['HTTP_HOST'];





Fortran: program HostTest
  character(len=128) :: name 
  call hostnm(name)
  print *, name
end program HostTest
Task: Hostname

C: #include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <unistd.h>
 
int main(void)
{
 char name[_POSIX_HOST_NAME_MAX + 1];
 return gethostname(name, sizeof name) == -1 || printf("%s\n", name) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}









COBOL:        identification division.
       program-id. hostname.

       data division.
       working-storage section.
       01 hostname pic x(256).
       01 nullpos  pic 999 value 1.

       procedure division.
       call "gethostname" using hostname by value length of hostname
       string hostname delimited by low-value into hostname
           with pointer nullpos
       display "Host: " hostname(1 : nullpos - 1)
       goback.
       end program hostname.
Task: Hostname



C#: System.Net.Dns.GetHostName();







COBOL:        identification division.
       program-id. hostname.

       data division.
       working-storage section.
       01 hostname pic x(256).
       01 nullpos  pic 999 value 1.

       procedure division.
       call "gethostname" using hostname by value length of hostname
       string hostname delimited by low-value into hostname
           with pointer nullpos
       display "Host: " hostname(1 : nullpos - 1)
       goback.
       end program hostname.
Task: Hostname





Java: import java.net.*;
class DiscoverHostName {
 public static void main(final String[] args) {
  try {
   System.out.println(InetAddress.getLocalHost().getHostName());
  } catch (UnknownHostException e) { 
  }
 }
}





COBOL:        identification division.
       program-id. hostname.

       data division.
       working-storage section.
       01 hostname pic x(256).
       01 nullpos  pic 999 value 1.

       procedure division.
       call "gethostname" using hostname by value length of hostname
       string hostname delimited by low-value into hostname
           with pointer nullpos
       display "Host: " hostname(1 : nullpos - 1)
       goback.
       end program hostname.
Task: Hostname







Python: import socket
host = socket.gethostname()



COBOL:        identification division.
       program-id. hostname.

       data division.
       working-storage section.
       01 hostname pic x(256).
       01 nullpos  pic 999 value 1.

       procedure division.
       call "gethostname" using hostname by value length of hostname
       string hostname delimited by low-value into hostname
           with pointer nullpos
       display "Host: " hostname(1 : nullpos - 1)
       goback.
       end program hostname.
Task: Hostname








VB: Set objNetwork = CreateObject("WScript.Network")
WScript.Echo objNetwork.ComputerName


COBOL:        identification division.
       program-id. hostname.

       data division.
       working-storage section.
       01 hostname pic x(256).
       01 nullpos  pic 999 value 1.

       procedure division.
       call "gethostname" using hostname by value length of hostname
       string hostname delimited by low-value into hostname
           with pointer nullpos
       display "Host: " hostname(1 : nullpos - 1)
       goback.
       end program hostname.
Task: Hostname




Go: package main

import (
	"fmt"
	"os"
)

func main() {
	fmt.Println(os.Hostname())
}






COBOL:        identification division.
       program-id. hostname.

       data division.
       working-storage section.
       01 hostname pic x(256).
       01 nullpos  pic 999 value 1.

       procedure division.
       call "gethostname" using hostname by value length of hostname
       string hostname delimited by low-value into hostname
           with pointer nullpos
       display "Host: " hostname(1 : nullpos - 1)
       goback.
       end program hostname.
Task: Hostname






PHP: echo $_SERVER['HTTP_HOST'];
Task: Hostname






PHP: echo $_SERVER['HTTP_HOST'];






Ada: with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Sockets;

procedure Demo is
begin
   Put_Line (GNAT.Sockets.Host_Name);
end Demo;
Task: Hostname






PHP: echo $_SERVER['HTTP_HOST'];




COBOL:        identification division.
       program-id. hostname.

       data division.
       working-storage section.
       01 hostname pic x(256).
       01 nullpos  pic 999 value 1.

       procedure division.
       call "gethostname" using hostname by value length of hostname
       string hostname delimited by low-value into hostname
           with pointer nullpos
       display "Host: " hostname(1 : nullpos - 1)
       goback.
       end program hostname.