Looking at your other question - How to Eliminate whitespaces while Reading a file in VHDL provides an example memory init file as well as a problem reading it.
Incorporating that fix and using the method method J.H. Bonarius suggests gives rise to a Minimal, Complete and Verifiable example:
library ieee;
use ieee.std_logic_1164.all;
PACKAGE io IS
type memory is array (natural range<>) of std_logic_vector(3 downto 0);
function iswhitespace (inpstr: in string) return boolean;
END;
package body io is
function iswhitespace (inpstr: in string) return boolean is
constant NBSP: character := character'val(128);
begin
for i in inpstr'range loop
if inpstr(i) /= ' ' and inpstr(i) /= NBSP and inpstr(i) /= HT then
exit;
elsif i = inpstr'RIGHT then
return TRUE;
end if;
end loop;
return FALSE;
end function;
end package body;
library ieee;
use ieee.std_logic_1164.all;
use work.io.all;
entity File_io is
generic (
constant MEMORY_SIZE: natural := 42;
constant filename: string := "C:\Users\ChowdaryS\Downloads\topo.bin"
);
port (
clk: in std_logic;
Data_memory: out memory (0 to MEMORY_SIZE - 1)
);
end entity;
architecture foo of File_io is
signal mem: memory (0 to MEMORY_SIZE - 1); -- ADDED subtype indication
use ieee.numeric_std.all; -- MISSING cntext item
use std.textio.all;
signal mem_inited: boolean := FALSE; -- ADDED
begin
process(clk)
file f: text open read_mode is filename;
variable L: line;
variable i: integer:= 0;
variable b: bit_vector(3 downto 0);
begin
if not mem_inited then
i := 0;
while not endfile(f) loop
readline(f, L);
while L.all'length >= b'length and not iswhitespace(L.all) loop
read(L, b);
mem(i) <= to_stdlogicvector(b);
i := i + 1;
end loop;
end loop;
report "mem values loaded = " & integer'image(i);
mem_inited <= TRUE;
end if;
end process;
Data_memory <= mem;
end architecture foo;
There are a changes. A function iswhitespace has been added to package io. You can see the above cited question for trade-offs and whether it's required.
The assignment to the output port has been moved outside the process. It's assumed you'll have some sort of writes to mem included in the process.
There's also a testbench that instantiates file_io and determines the size of the memory array, passing that as a generic.
library ieee;
use ieee.std_logic_1164.all;
use work.io.all;
entity file_io_tb is
end entity;
architecture foo of file_io_tb is
constant MEMSIZ: natural := 16;
constant filename: string := "topo.bin"; -- found locally.
signal clk: std_logic := '0';
signal Data_memory: memory (0 to MEMSIZ - 1);
use std.textio.all;
impure function getarraysize return natural is
variable L: Line;
variable i: natural;
variable b: bit_vector (3 downto 0);
file f: text open read_mode is filename;
begin
i := 0;
while not endfile(f) loop
readline(f, L);
while L.all'length >= b'length and not iswhitespace(L.all) loop
read(L, b);
i := i + 1;
end loop;
end loop;
report " memory size = " & integer'image(i);
return i;
end function;
begin
DUT:
entity work.file_io
generic map (MEMORY_SIZE => getarraysize, filename => filename)
port map (
clk => clk,
Data_memory => Data_memory
);
CLOCK:
process
begin
wait for 10 ns;
clk <= not clk;
if now > 50 ns then
wait;
end if;
end process;
end architecture;
The function is performs the file read at elaboration time to set a generic.
And we see this initializes mem:

The copy of topo.bin used has four trailing spaces on the first line:
10101100 11010100 10101100 11010100
11111110 10111001 11111110 10111001
The values shown in the waveform match the above two lines from topo.bin.
(And all this got written to find the issue with whitespace in the other question).